熊猫value_counts显示重复

时间:2020-04-13 01:23:06

标签: pandas-groupby

这是我正在使用的代码

all_data.groupby('BsmtFullBath').BsmtFullBath.count()

输出为

BsmtFullBath
0     856
1     588
2      15
3       1
0     849
1     584
2      23
3       1
NA      2
Name: BsmtFullBath, dtype: int64

期望每个值都有唯一的值,但是“ 0”将出现两次。

1 个答案:

答案 0 :(得分:0)

我相信如果你想摆脱重复的值,就像下面的例子一样使用 map 函数,只需 ch

df_final['DC'] = df_final['DC'].map({'NO':0, 'WT':1, 'BU':2,'CT':3,'BT':4, 'CD':5})