更改日期框架的尺寸

时间:2018-09-08 10:45:18

标签: python pandas dataframe

This is my dataframe

我有一个具有MultiIndex且尺寸为18 x 1的数据框。我想获得一个尺寸为6 x 3的数据框,其中航空公司名称为行索引,情感为负,中性和正数作为列名。最快的方法是什么?

我在这里有一个数据示例:

idx = pd.MultiIndex.from_product([['airline_1', 'airline_2', 'airline_3','airline_4', 'airline_5', 'airline_6'],
                                  ['negative', 'neutral', 'positive']],
                                 names=['airline', 'sentiment'])
col = ['test']
df = pd.DataFrame('-',idx,col)
test = []
for i in range(18):
    test.append(i)
df['value'] = test
df = df.drop('test', axis = 1)

1 个答案:

答案 0 :(得分:0)

一旦您知道方法,这就很简单:
只需<string name="facebook_app_id" translatable="false">123456789</string> 就能带您到这里:)

要摆脱MultiIndex作为列的影响,只保留情感得分,请执行以下操作:

df.unstack()