Python - 查找 Pandas DataFrame 的统计信息摘要
要查找 DataFrame 的统计信息摘要,请使用describe()方法。首先,我们导入了以下带有别名的pandas库
import pandas as pd
以下是我们的 CSV 文件,我们正在创建一个 Pandas DataFrame -
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\CarRecords.csv")
现在,获取我们的 Pandas DataFrame 的统计摘要 -
dataFrame.describe()
示例
以下是完整代码
import pandas as pd输出结果# 读取csv文件
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\CarRecords.csv")
print("DataFrame...\n",dataFrame)
# 计算 DataFrame 中的行和列
print("\nNumber of rows and column in our DataFrame = ",dataFrame.shape)
# 数据框摘要
print("\nGet the summary of statistics of a DataFrame = \n",dataFrame.describe())
# 返回前 7 行记录
print("\nDataFrame with specific number of rows...\n",dataFrame.head(7))
这将产生以下输出
DataFrame...Car Place UnitsSold
0 Audi Bangalore 80
1 Porsche Mumbai 110
2 RollsRoyce Pune 100
3 BMW Delhi 95
4 Mercedes Hyderabad 80
5 Lamborghini Chandigarh 80
6 Audi Mumbai 100
7 Mercedes Pune 120
8 Lamborghini Delhi 100
Number of rows and colums in our DataFrame = (9, 3)
Get the summarry of statistics of a DataFrame =
UnitsSold
count 9.000000
mean 96.111111
std 14.092945
min 80.000000
25% 80.000000
50% 100.000000
75% 100.000000
max 120.000000
DataFrame with specific number of rows ...
Car Place UnitsSold
0 Audi Bangalore 80
1 Porsche Mumbai 110
2 RollsRoyce Pune 100
3 BMW Delhi 95
4 Mercedes Hyderabad 80
5 Lamborghini Chandigarh 80
6 Audi Mumbai 100
以上是 Python - 查找 Pandas DataFrame 的统计信息摘要 的全部内容, 来源链接: utcz.com/z/335497.html