0

我有一个包含 6 个不同变量的“部门”列的数据框。

但是,当我创建一个新的 df 时,使用:

indicator = dept.groupby('Department')[['Assignment Status']].count()

df 包含两个“R&D Operations”条目:

Department          Assignment Status

Business Services   17616
Operations          112958
Quality Assurance   28070
Quality Control     32860
R&D Operations      63206
R&D Operations      275

这一定是与我原来的 df 的某种格式差异。如何将“部门”列中的这两个条目结合起来。

非常感谢

4

1 回答 1

1

我相信这个问题一定是因为@CypherX 和@Dani 建议的值中有空格

# To remove the white spaces from both ends (left and right)

dept.Department = dept.Department.str.strip() 

# Then perform the groupby operation

indicator = dept.groupby('Department')[['Assignment Status']].count()

于 2020-11-21T12:51:48.740 回答