1

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

2 Answers 2

1

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

new.rename('value').rename_axis('color').reset_index()
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

new.reset_index(name='Value')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.