加入后访问多索引列时遇到问题
trouble accessing multi index column after join
我创建了以下多索引列:
Out[213]:
KEY POLL
count mean sum
0 1 21 0.80921 10
1 2 3 0.666667 2
2 3 67 0.835821 3
3 4 13 1.000000 4
4 5 674 0.876855 5
如果需要,我可以访问 POLL 多索引列:
session_counts_merged[('POLL','sum')].head()
Out[225]:
0 0
1 0
2 0
3 0
4 0
Name: (POLL, sum), dtype: int64
然而,当我将上面的 table 与另一个加入时,我不知道如何访问 table 了。
这是新 table:
上的 .info()
account_aggregates.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 9713 entries, 0 to 9712
Data columns (total 6 columns):
NATIVEACCOUNTKEY 9713 non-null int64
(NATIVEACCOUNTKEY, ) 9713 non-null int64
(POLL, count) 9713 non-null int64
(POLL, mean) 9713 non-null float64
(POLL, sum) 9713 non-null int64
session_deciles 9713 non-null object
如何访问名为 (POLL, sum) 的列?做这样的事情:
account_aggregates_grouped['(POLL, sum)'].head()
导致找不到密钥错误
'(POLL, sum)'
是一个字符串。
('POLL','sum')
是一个包含两个字符串的元组。
具有 MultiIndex 的 DataFrame 具有由标签组成的 元组 的键
从每个指标水平。因此,改变
account_aggregates_grouped['(POLL, sum)'].head()
到
account_aggregates_grouped[('POLL', 'sum')].head()
我创建了以下多索引列:
Out[213]:
KEY POLL
count mean sum
0 1 21 0.80921 10
1 2 3 0.666667 2
2 3 67 0.835821 3
3 4 13 1.000000 4
4 5 674 0.876855 5
如果需要,我可以访问 POLL 多索引列:
session_counts_merged[('POLL','sum')].head()
Out[225]:
0 0
1 0
2 0
3 0
4 0
Name: (POLL, sum), dtype: int64
然而,当我将上面的 table 与另一个加入时,我不知道如何访问 table 了。
这是新 table:
上的 .info()account_aggregates.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 9713 entries, 0 to 9712
Data columns (total 6 columns):
NATIVEACCOUNTKEY 9713 non-null int64
(NATIVEACCOUNTKEY, ) 9713 non-null int64
(POLL, count) 9713 non-null int64
(POLL, mean) 9713 non-null float64
(POLL, sum) 9713 non-null int64
session_deciles 9713 non-null object
如何访问名为 (POLL, sum) 的列?做这样的事情:
account_aggregates_grouped['(POLL, sum)'].head()
导致找不到密钥错误
'(POLL, sum)'
是一个字符串。
('POLL','sum')
是一个包含两个字符串的元组。
具有 MultiIndex 的 DataFrame 具有由标签组成的 元组 的键
从每个指标水平。因此,改变
account_aggregates_grouped['(POLL, sum)'].head()
到
account_aggregates_grouped[('POLL', 'sum')].head()