df.info()不显示有关数据框的任何信息

时间:2019-06-12 10:17:56

标签: python-2.7

我跑步时

print df

结果

   A   B   C   D
   0   4   8   4-a
   7   3   5   3-b

当我只选择一列时

print df['D']

什么都没显示

print df.info()

什么都没显示

我不知道是怎么了? 我使用此代码设置数据

import pandas as pd

data = {'A': {0: 0, 1: 4, 2: 5, 3: 6, 4: 7, 5: 7, 6: 6},
        'B': {0: 's', 1: 's', 2: 's', 3: 's', 4: 's', 5: 's', 6: 's'},
        'C': {0: 3, 1: 2, 2: 2, 3: 1, 4: 2, 5: 3, 6: 0},
        'D': {0: 'a', 1: 'a', 2: 'a', 3: 'a', 4: 'b', 5: 'b', 6: 'b'}}
df = pd.DataFrame(data)

# Handling column A (first index per value in D)
output_df = df.drop_duplicates(subset='D', keep='first')

# Itering through rows
for index, row in output_df.iterrows():

    #Calcultating the counts in B
    output_df.loc[index, 'B'] = df[df.D == row.D].B.count()

    #Calcultating the sum in C
    output_df.loc[index, 'C'] = df[df.D == row.D].C.sum()

#Finally changing values in D by concatenating values in B and D
output_df.loc[:, 'D'] = output_df.B.map(str) + "-" +  output_df.D

0 个答案:

没有答案