简体   繁体   English

如何从 output 代码中删除名称和数据类型?

[英]How to remove name and dtype from output code?

I was wondering how to remove the "name" and "dtype: float64" from the output?我想知道如何从 output 中删除“名称”和“dtype:float64”? I am a beginner at Python so I'm not sure how!我是 Python 的初学者,所以我不确定怎么做!

I have to find the mean, median, and standard deviation grouped by 3 different categorical variables.我必须找到按 3 个不同分类变量分组的均值、中值和标准差。 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.我的 dataframe 图片随我的代码一起附上。 Thank you in advance!先感谢您!

My dataframe My code我的 dataframe我的密码

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:您可以像这样使用to_string

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

#or

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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