@@ -97,22 +97,58 @@ columns, this is equivalent to passing a
97
97
98
98
``HDFStore `` now serializes MultiIndex dataframes when appending tables.
99
99
100
- .. ipython :: python
101
-
102
- index = MultiIndex(levels = [[' foo' , ' bar' , ' baz' , ' qux' ],
103
- [' one' , ' two' , ' three' ]],
104
- labels = [[0 , 0 , 0 , 1 , 1 , 2 , 2 , 3 , 3 , 3 ],
105
- [0 , 1 , 2 , 0 , 1 , 1 , 2 , 0 , 1 , 2 ]],
106
- names = [' foo' , ' bar' ])
107
- df = DataFrame(np.random.randn(10 , 3 ), index = index,
108
- columns = [' A' , ' B' , ' C' ])
109
- df
110
-
111
- store.append(' mi' ,df)
112
- store.select(' mi' )
113
-
114
- # the levels are automatically included as data columns
115
- store.select(' mi' , " foo='bar'" )
100
+ .. code-block :: ipython
101
+
102
+ In [19]: index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
103
+ ....: ['one', 'two', 'three']],
104
+ ....: labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
105
+ ....: [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
106
+ ....: names=['foo', 'bar'])
107
+ ....:
108
+
109
+ In [20]: df = DataFrame(np.random.randn(10, 3), index=index,
110
+ ....: columns=['A', 'B', 'C'])
111
+ ....:
112
+
113
+ In [21]: df
114
+ Out[21]:
115
+ A B C
116
+ foo bar
117
+ foo one -0.116619 0.295575 -1.047704
118
+ two 1.640556 1.905836 2.772115
119
+ three 0.088787 -1.144197 -0.633372
120
+ bar one 0.925372 -0.006438 -0.820408
121
+ two -0.600874 -1.039266 0.824758
122
+ baz two -0.824095 -0.337730 -0.927764
123
+ three -0.840123 0.248505 -0.109250
124
+ qux one 0.431977 -0.460710 0.336505
125
+ two -3.207595 -1.535854 0.409769
126
+ three -0.673145 -0.741113 -0.110891
127
+
128
+ In [22]: store.append('mi',df)
129
+
130
+ In [23]: store.select('mi')
131
+ Out[23]:
132
+ A B C
133
+ foo bar
134
+ foo one -0.116619 0.295575 -1.047704
135
+ two 1.640556 1.905836 2.772115
136
+ three 0.088787 -1.144197 -0.633372
137
+ bar one 0.925372 -0.006438 -0.820408
138
+ two -0.600874 -1.039266 0.824758
139
+ baz two -0.824095 -0.337730 -0.927764
140
+ three -0.840123 0.248505 -0.109250
141
+ qux one 0.431977 -0.460710 0.336505
142
+ two -3.207595 -1.535854 0.409769
143
+ three -0.673145 -0.741113 -0.110891
144
+
145
+ # the levels are automatically included as data columns
146
+ In [24]: store.select('mi', "foo='bar'")
147
+ Out[24]:
148
+ A B C
149
+ foo bar
150
+ bar one 0.925372 -0.006438 -0.820408
151
+ two -0.600874 -1.039266 0.824758
116
152
117
153
Multi-table creation via ``append_to_multiple `` and selection via
118
154
``select_as_multiple `` can create/select from multiple tables and return a
0 commit comments