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

Seaborne Bar Plot Median Estimator Error
Python Pandas groupby-apply strange behavior
Converting a list of key value pairs to table format in iPython
Why is column name in dataframe have symbols next to it?
Pandas: pad series on top or bottom
Creating new pandas columns containing count of distinct entries
Pandas Ffill on rows that contain only NaN
Pandas dataframe: drop all the rows based one column value with python
pandas pivot_table with dates as values
Pandas - strange rounding with float64 data
Fill missing Values by a ratio of other values in Pandas
pandas divide df n x m by series length g by index
pandas dataframe to spark dataframe “Can not merge type error”
Why is column name not going over actual column and creating new columns in dataframe?
How to get rid of the numbers at the top of column names in Dataframe?
NumPy/Pandas: convert array of “steps” into bool mask

Categories

HOME
arduino-uno
magnific-popup
minimum-spanning-tree
mfc
fft
rsyslog
sqlite3
fingerprint
append
gitpitch
python-unittest
vifm
spring-kafka
nstableview
etl
hapi
karma-jasmine
reverse-proxy
visjs
abi
autosys
emgucv
opennlp
microsoft-sync-framework
centos6.5
poltergeist
strncpy
typo3-6.2.x
wtx
webkitspeechrecognition
google-cloud-nl
tasklet
fog
copying
vsts-build-task
subset-sum
openoffice.org
xmlreader
google-api-nodejs-client
android-ble
file-format
neuroscience
serverside-rendering
code-search-engine
sqlite2
ansible-playbook
awt
email-templates
powershell-dsc
eigenvalue
turbogears
btrace
revapi
paxos
dandelion
hls.js
mplayer
snmptrapd
jspdf-autotable
bind9
dwscript
angular-strap
google-feed-api
angular-cache
azure-virtual-network
trash
asp.net-4.5
skobbler-maps
tcpserver
vhd
t4mvc
atk4
muse
deis
ideamart
arcanist
interrupted-exception
angular-local-storage
dereference
skos
relocation
id3v2
device-manager
xojo
dml
yorick
poller
app42
centos5
uv-mapping
runtime.exec
dbconnection
orchardcms-1.7
frameset
propertyeditor
datawindow
netbeans-6.9
bigcouch
horizontal-accordion
netbeans-7.1
telerik-scheduler
remember-me
fluent-interface
sproutcore-2
gin
adrotator
data-driven

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