pandas


Copy numpy array into Panda multiindex (same size)


I have two matrix: numpy square matrix and a panda multiindexed square matrix. They are the same size. The idea is to get the value from numpy into the multiindex panda matrix to navigate more easily into the data.
My matrix are around 100 000 x 100 000.
And my panda matrix has three level of index.
tuples = [('1','A','a'), ('1','A','b'), ('1','A','c'), ('1','B','a'), ('1','B','b'), ('1','B','c'), ('2','A','a'), ('2','A','b'), ('2','B','a')]
index = pd.MultiIndex.from_tuples(tuples, names=['geography', 'product','activity'])
df = pd.DataFrame(index=index, columns=index)
geography 1 2
product A B A B
activity a b c a b c a b a
geography product activity
1 A a 0 0 0 0 0 0 0 0 0
b 0 0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 0 0 0
B a 0 0 0 0 0 0 0 0 0
b 0 0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 0 0 0
2 A a 0 0 0 0 0 0 0 0 0
b 0 0 0 0 0 0 0 0 0
B a 0 0 0 0 0 0 0 0 0
np.random.rand(9,9)
array([[ 0.27302806, 0.33926193, 0.01489047, 0.71959889, 0.43500806,
0.03607795, 0.03747561, 0.43000199, 0.8091691 ],
[ 0.96626878, 0.37613022, 0.7739084 , 0.16724657, 0.01144436,
0.0107722 , 0.73513494, 0.13305542, 0.2910334 ],
[ 0.00622779, 0.93699165, 0.62725798, 0.25009469, 0.14010666,
0.61826728, 0.72060106, 0.58864557, 0.29375779],
[ 0.14937979, 0.45269751, 0.68450964, 0.15986812, 0.69879559,
0.06573519, 0.57504452, 0.49540882, 0.77283616],
[ 0.60933817, 0.2701683 , 0.69067959, 0.22806386, 0.79456502,
0.75107457, 0.2805325 , 0.27659171, 0.33446821],
[ 0.82860687, 0.27055835, 0.37684942, 0.18962783, 0.59885119,
0.31246936, 0.94522335, 0.53487273, 0.00611481],
[ 0.27683582, 0.23653112, 0.41250374, 0.5024068 , 0.27621212,
0.81379001, 0.6704781 , 0.87521485, 0.04577144],
[ 0.95516958, 0.21844023, 0.86558273, 0.52300142, 0.91328259,
0.7587479 , 0.15201837, 0.15376074, 0.12092142],
[ 0.36835891, 0.0381736 , 0.36473176, 0.30510363, 0.19433639,
0.43431018, 0.00112607, 0.35334684, 0.82307449]])
How I can put the value of the numpy matrix into in the panda multiindex matrix. The two matrix by construction have the same structure, i.e. the numpy matrix is the panda one without label indexes.
I found a dozen of examples to transform multiindex df into numpy array, but not in this way. Only one example of a 3 dimensional numpy array, but mine is not a 3-d np array.
Thanks to Divakar.
Something, just df[:] = np.random.rand(9,9) and it is all right.

Related Links

Groupby function on pandas dataframe
How are the nan values filled in x.add(y, fill_value = 0)?
mulitiindexing in python: how to select level0-index based on multiple values in level1 rows
What's the Pandas way to write `if()` conditional between two `timeseries` columns?
dask read_csv upcasts bool to object
Proper way to use to_latex with both textstyle math and escaped text elsewhere
Convert ordered levels to numeric in pandas
Counting the total number of categorial values in a column for an entire dataframe
Finding max date of the month in a list of pandas timeseries dates
How to change dataframe font size in jupiter notebook to latex conversion?
Pandas Dataframe aggregate different groups of columns
select rows based on rows in second column
Element wise multiplication of each row
pandas | propagate values for all dates
pandas fill missing value with median given group
Filtering out dataframes from a dictonary, that fufill a condition

Categories

HOME
ms-access
java
xamarin
vbscript
keycloak
heroku
homebrew
office365api
relay
android-4.4-kitkat
getelementsbytagname
amortized-analysis
sqlite3
icloud
disassembler
angular-ui-bootstrap
convolution
uber-api
basic
primary-key
ssl-client-authentication
quickfix
progressive-web-apps
transformation
invantive-sql
google-pagespeed
jprofiler
jtextfield
xlsxwriter
physics-engine
abi
tar
ehcache
web-sql
sox
p-value
fish
facet
user-interaction
web-api-testing
elasticsearch-ruby
large-file-upload
vision
bcd
ecto
textmate
ghost4j
google-api-nodejs-client
http-digest
gesture
android-browser
webdriver-manager
angularjs-factory
leading-zero
node-gyp
isbn
checkboxlist
komodoedit
python-webbrowser
typescript1.8
dotnetzip
fancybox-2
svmlight
brightcove
pillow
nbconvert
jquery-filter
gridpane
httplistener
underscore.js-templating
etsy
gstreamer-0.10
ford-fulkerson
freedesktop.org
tcpserver
msys
ora-00900
django-unittest
dukescript
createprocessasuser
census
relocation
javafx-webengine
code-access-security
jubula
viadeo
gnu-smalltalk
c18
oam
web2py-modules
dotnetnuke-5
shellexecute
html4
sabredav
gil
labwindows
viewswitcher
window-management
pydot
xmlspy
cinema-4d
file-comparison
inotifycollectionchanged
pyinotify
site.master
fluent-interface
vc90
ncqrs
noscript
genealogy
lzh

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App