python - Groupby to Dataframe in Pandas -


basically, use excel file contains thousands of data , i'm using pandas read in file.

import pandas pd agg = pd.read_csv('station.csv', sep = ',') 

then did grouped data accordingly these categories,

month_station = agg.groupby(['month','stationname']) 

the groupby not used counting mean, median or etc aggregating data in terms of month , station name. it's question wants

now, want output month_station excel file first need transfer groupby dataframe.

i've seen examples:

pd.dataframe(month_station.size().reset_index(name = "group_count")) 

but thing is, don't require size/count of data grouping in terms of month , station name not require count or sorts. tried removing size() , gives me error.

i want content of month_station ported dataframe proceed , output csv file seemed complicated.

the nature of groupby can derive aggregate calculation, such mean or count or sum or etc. if merely trying see on of each pair of month , station name, try this:

month_station = agg.groupby(['month','stationname'],as_index=false).count() month_station = month_station['month','stationname'] 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -