Get values from pandas.core.groupby.generic.DataFrameGroupBy object

Hi So I have dataframe like this, which has 71 unique values in time column, 721 unique values in lat column, 1440 unique values in lon column and all the values in temp column are unique.

Dataframe Sample:

  time        latitude  longitude       temp
1950-01-01      90.0     0.00         49654.792969
1950-01-01      90.0     0.25         49654.792969
   .              .       .                .
   .              .       .                .
73715040 rows * 4 cloumn

Now I want to groupby using lat and lon column to get all the values of temp across all time period for all grid or pairs which will have 1038240 rows(721 lat*1440 lon), so I’m doing like this.

df = df.groupby(['latitude', 'longitude'])

Now as it is pandas.core.groupby.generic.DataFrameGroupBy object I’m not able to access the values from it. So I’m trying to convert it into dataframe by df.apply(pd.DataFrame) but this is taking lot of time and my kernel is getting crash. So is there any other way to get the records, or am I doing something wrong here. Please suggest alternate way if possible.


This should work for you:

df.groupby(['latitude', 'longitude']).aggregate(lambda x: ','.join(map(str, x)))

Leave a Reply

Your email address will not be published. Required fields are marked *