Home > Blockchain >  convert pandas output to pandas dataframe
convert pandas output to pandas dataframe

Time:12-28

I extracted a short calculation from a dataset and got the output below. I want to convert this output to a dataframe and rename the column name. Below is my code

This is the extraction

b = df.groupby('Color').size() 
a = df_copy.groupby(['Color'])['events'].sum()
new = round(a/b)

This is the output

Color
blue                13.0
red                 73.0
green               54.0
white               178.0
black               59.0
yellow              78.0
dtype: float64

How can i rename the both columns and convert to a dataframe ?

Thank you

CodePudding user response:

What you have is a pd.Series. Try this:

new.rename('value').rename_axis('color').reset_index()

CodePudding user response:

try this:

new.reset_index(name='Value')
  • Related