- value_counts()是一种查看表格某列中有多少个不同值的快捷方法,并计算每个不同值有在该列中有多少重复值。
import pandas as pd
import numpy as np
df1= DataFrame(
{"handsome":["timo","anni","timo"],
"smart":["mike","anni","mike"]}
)
print(df1)
'''
handsome smart
0 timo mike
1 anni anni
2 timo mike
'''
df1.apply(pd.value_counts)##数据框要借助apply来应用value_counts()
'''
handsome smart
anni 1.0 1.0
mike NaN 2.0
timo 2.0 NaN
'''
import pandas as pd
import numpy as np
from pandas import DataFrame
from pandas import Series
s1=Series(["timo","mike","anni","timo"])
s1.value_counts()
'''
timo 2
mike 1
anni 1
dtype: int64
'''
标签:mike,value,anni,import,counts,timo
From: https://www.cnblogs.com/old-lei/p/16907968.html