gpt4 book ai didi

python - python中的describe(包括 'top')中的='all'函数有什么用?

转载 作者:行者123 更新时间:2023-11-30 21:58:34 26 4
gpt4 key购买 nike

import pandas as pd
import numpy as np
#Create a Dictionary of series
d =
{'Name':pd.Series(['Tom','James','Ricky','Vin','Steve','Smith','Jack',
'Lee','David','Gasper','Betina','Andres']),
'Age':pd.Series([25,26,25,23,30,29,23,34,40,30,51,46]),
'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8,3.78,
2.98,4.80,4.10,
3.65])
}
#Create a DataFrame
df = pd.DataFrame(d)
print(df.describe(include='all'))

如果运行此代码,我会得到以下输出:

      Name        Age     Rating

count 12 12.000000 12.000000
unique 12 NaN NaN
top Betina NaN NaN
freq 1 NaN NaN
mean NaN 31.833333 3.743333
std NaN 9.232682 0.661628
min NaN 23.000000 2.560000
25% NaN 25.000000 3.230000
50% NaN 29.500000 3.790000
75% NaN 35.500000 4.132500
max NaN 51.000000 4.800000

当我每次顶级函数发生变化时运行代码时。输出中 top 函数的用途是什么?它将如何工作?

最佳答案

what is the purpose of top function in output, and how it will work?

如果执行:

df.Name.value_counts()

你会在 Name 中看到一个人的值(value)列及其计数。 top 给出分类值的最高计数值。

示例:

d ={'Name':pd.Series(['Tom','Steve','Ricky','Vin','Steve','Smith','Jack',
'Lee','David','Gasper','Betina','Andres']),
'Age':pd.Series([25,26,25,23,30,29,23,34,40,30,51,46]),
'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8,3.78,
2.98,4.80,4.10,
3.65])
}
#Create a DataFrame
df = pd.DataFrame(d)
print(df.describe(include='all'))

Name Age Rating
count 12 12.000000 12.000000
unique 11 NaN NaN
top Steve NaN NaN
freq 2 NaN NaN
mean NaN 31.833333 3.743333
std NaN 9.232682 0.661628
min NaN 23.000000 2.560000
25% NaN 25.000000 3.230000
50% NaN 29.500000 3.790000
75% NaN 35.500000 4.132500
max NaN 51.000000 4.800000

print(df.Name.value_counts())

Steve 2
Ricky 1
Tom 1
Andres 1
Jack 1
Smith 1
Lee 1
Betina 1
Vin 1
Gasper 1
David 1

Name计数 Steve最高,它位于顶部。

关于python - python中的describe(包括 'top')中的='all'函数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54885821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com