美文网首页我爱编程
python pandas对Dataframe某一列运用数据透视

python pandas对Dataframe某一列运用数据透视

作者: tommyjex | 来源:发表于2018-03-06 22:17 被阅读0次

统计数据表格中‘状态’列中有哪几类状态,每个状态出现了多少次

import pandas as pd
import numpy as np

df = pd.read_csv('C:/python/pandas/broadband_bundle_O365_171225.csv', encoding='utf-8')
df_nona_row = df.dropna(axis=0,how='all')
df_nona = df_nona_row.fillna('missing')
index = np.arange(len(df_nona['状态']))
table = pd.pivot_table(df_nona,index=['状态'],values=['联系人'],aggfunc='count')
print(table)

上述代码段 aggfunc='count',表示对状态列中出现的每个值计数。
aggfunc还可以取值sum,mean等

相关文章

网友评论

    本文标题:python pandas对Dataframe某一列运用数据透视

    本文链接:https://www.haomeiwen.com/subject/pyqdfftx.html