[英]Change pandas data frame to add max column -> maximum value for each month of the year from a data frame in pandas. How can I do this?
[英]How do I get count of each value from a pandas Data Frame column if the column elements is a set?
我有一個數據集,其中有一列的元素如下所示
index set_column
0 {5520986, 5520236}
1 {5520986, 5520236}
2 {5471829, 5515351}
3 {5471829, 5515351}
4 {5471829, 5515351}
5 {5471829, 5515351}
6 {5471829, 5515351}
7 {5471829, 5515351}
我想要得到的是每個唯一值的計數。
set count
{5520986, 5520236} 2
{5471829, 5515351} 6
你可以做:
df = df["set_column"].value_counts().reset_index()
df.columns = ["set", "count"]
print(df)
Output:
set count
0 {5471829, 5515351} 6
1 {5520986, 5520236} 2
你可以簡單地試試這個
df['Count']=df.groupby().cumcount()
df=df.groupby(['set_column'].max()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.