0

I am trying to group by different country and ID in pandas and calculate the mean,size,max,min values of "value1" and "value2". The intention is to insert the new pandas table in an SQL table while also showing the country and ID.

However, when I use the below code, it is not creating a new table with country and ID but only showing the mean,sum,max and size of the values.

df1 = df.groupby(['country', 'id']).agg({
                'value1': ['size', 'sum', 'mean', 'max', 'min'],
                'value2': ['size', 'sum', 'mean', 'max', 'min'],        
            })
            df1.to_sql("test", con=my_engine, if_exists='replace', index=False)

Further the column names are being written as

"('kills','min)".

"('kills','max)".

So my question is: How do I rename the column names and how do I add country and ID as columns as well?

Community
  • 1
  • 1
MathiasRa
  • 825
  • 2
  • 12
  • 24

0 Answers0