简体   繁体   中英

How to remove name and dtype from output code?

I was wondering how to remove the "name" and "dtype: float64" from the output? I am a beginner at Python so I'm not sure how!

I have to find the mean, median, and standard deviation grouped by 3 different categorical variables. I figured out how to do that, but I want to get rid of the name and dtype at the bottom.

My dataframe image is attached along with my code. Thank you in advance!

My dataframe My code

Here's my code in typed version as well:

print(f"Mean:{df['Depression_Score'].groupby(df['Treatment_Type']).mean()}")
print(f"\nMedian:{df['Depression_Score'].groupby(df['Treatment_Type']).mean()}")
print(f"\nSD:{df['Depression_Score'].groupby(df['Treatment_Type']).mean()}")`

Thanks again!

You can use to_string like this:

df['Depression_Score'].groupby(df['Treatment_Type']).mean().to_string()

#or

print(f"Mean:{df['Depression_Score'].groupby(df['Treatment_Type']).mean().to_string()}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM