此问题在此处已有答案:
Turn Pandas Multi-Index into column(8个答案)
4天前关闭。
当使用pandas库来解释数据集时,我试图通过使用value_counts(subset =...)来对dataframe的2列中的所有对进行求和。不幸的是,它总是在结果中给我不应该在那里的空格,并使输出不可读。有人知道如何避免这种情况吗?
尝试:
clm = [ 'class',' cap-shape','cap-surface','cap-color','bruises?',' odor','gill-attachment',' gill-spacing','gill-size',' gill-color','stalk-shape',' stalk-root','stalk-surface-above-ring',' stalk-surface-below-ring','stalk-color-above-ring','stalk-color-below-ring','veil-type',' veil-color','ring-number','ring-type','spore-print-color',' population ','habitat' ]
myTable = pd.read_csv(file_path, header=None, names=clm)
print(myTable.value_counts(subset = ['class', 'cap-color']))
结果:
result table
不应该有任何空格,每行应该有一个“p”或“e”
1条答案
按热度按时间hpxqektj1#
在value_counts()中设置参数normalize=False