![](/img/trans.png)
[英]Using Python, how do I remove duplicates in a PANDAS dataframe column while keeping/ignoring all 'nan' values?
[英]Removing duplicates with ignoring case sensitive and adding the next column values with the first one in pandas dataframe in python
我有一個df,
Name Count
Ram 1
ram 2
raM 1
Arjun 3
arjun 4
我想要的輸出df,
Name Count
Ram 4
Arjun 7
我試過groupby但是我無法達到所需的輸出,請幫忙
In [71]: df.assign(Name=df['Name'].str.capitalize()).groupby('Name', as_index=False).sum()
Out[71]:
Name Count
0 Arjun 7
1 Ram 4
如果我按title
格式化字符串分組,它簡化了我必須采取的步驟。
df.Count.groupby(df.Name.str.title()).sum().reset_index()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.