Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

Python - Using GroupBy on Pandas DataFrame returns numbers instead of values

I have a large dataset with over 50 columns and 30,000 rows. One of those columns is "Region" and has the following possible values ["Europe", "Americas", "Asia"]

I wanted to create a simple table which groups all the regions and counts how many instances there are. This is the code I am using

df_grouped = df.groupby('Region')['Date'].count()

I instead get a table like this:

Region          Date
1,0000.00        1
10,000.00        1
10,300.00        1
134,104,360.34   1
....            ....
iA               1
iBBB-            2
null            30

Can someone explain to me why this happens? I tried with other columns and I get similar results. I expected the table just have 3 rows with the total count indicated on the right hand side.

Thanks

question from:https://stackoverflow.com/questions/65834971/python-using-groupby-on-pandas-dataframe-returns-numbers-instead-of-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try:

df_grouped = df.groupby('Region').size()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...