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

Updating Bokeh figure with pandas dataframe queries
How to count multiple columns based on conditions
How to properly apply a lambda function into a pandas data frame column
Scikit-learn prediction intervals for future values?
Pandas: error when implementing Rpy2
Why this errror appears during fit while creating decision Tree Classifier
fill next 2 row with current row value pandas dataframe
equality of Pandas index objects with different dtypes and elements
Getting error while making column using DataFrame and Pandas
Pandas : combine rows of a dataframe with a list
Pandas timedelta from string
GroupBy'ed dataframe to numpy 3d array
pandas update/replace from different data frame
Optimizing sending a dataframe to hdf?
Alternative Google Analytics IO with Pandas
Scipy maximize with constraints

Categories

HOME
maven
ibm-bluemix
sendgrid
google-chrome-extension
openlayers
ngrx
mfc
octobercms
gis
adb
react-redux
spring-jdbc
jxls
baqend
azure-storage-tables
android-youtube-api
amazon-cloudformation
awesome-wm
dax
handsontable
remote-access
visual-studio-2005
flask-wtforms
windows-server-2012
solaris-10
oracle-coherence
wkwebview
microsoft-r
wijmo
lcd
autosys
underflow
wpfdatagrid
user-interaction
phpfox
wtx
msys2
preg-match
frame
http-get
framemaker
avcapturesession
form-data
rotational-matrices
main
az-application-insights
bootstrapper
sql-server-agent
estimote
heightmap
outlook-api
osx-mavericks
filepicker
jlink
winscp-net
carrot
tactic
feeds
pearson
flow-control
background-service
url-masking
player
gridview-sorting
php-parse-error
oauth2client
associative-array
jfugue
collapse
jmeter-maven-plugin
simple-framework
wordml
emailrelay
riak-cs
microbenchmark
android-nested-fragment
mdt
wordpress-theme-customize
socketexception
google-reader
aapt
dml
valueconverter
system.net.webexception
android-2.2-froyo
multiprocessor
pygit2
libstdc++
rdoc
bluepill
getmessage
bubble-chart
fireworks
gnustep
oncheckedchanged
lang
radcombobox
suppress
perfect-hash
fixed-width
backcolor
nerddinner
post-build

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