简体   繁体   English

如何将控制台上显示的矩阵保存为 Excel 文件

[英]How to save the matrix displayed on console as an Excel file

I know how to get the statistics from a data frame, but I do not know how to export them from Console.我知道如何从数据框中获取统计信息,但我不知道如何从控制台导出它们。

For example, I have a data frame, let us say that is called "df", then I obtained the statistics by the function of.describe().比如我有一个数据框,假设它叫“df”,那么我通过.describe()的function得到统计信息。 The results displayed on Console.结果显示在控制台上。 But I have no idea how to save the matrix displayed on Console as an excel file.但我不知道如何将控制台上显示的矩阵保存为 excel 文件。

print(df.describe(include=["object"])) 

Use another df to store the describe()使用另一个 df 来存储 describe()

new_df = df.describe()
new_df.to_excel("df_describe.xlsx")

It may work in one line:它可以在一行中工作:

df.describe(include=["object"]).to_excel('path/to/file.xlsx')

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html

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

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