pandas查看属性和数据

10.2 查看其属性、概览

1.属性

df.shape # 查看形状,⾏数和列数
df.dtypes # 查看数据类型
df.index # ⾏标签
df.columns # 列标签
df.values # 对象值,⼆维ndarray数组
df.size # DataFrame中的元素数量
df.ndim # 轴的数量,也指数组的维数
df.empty # DataFrame中没有数据或者任意坐标轴的长度为0,则返回True
df.axes # 返回一个仅以行轴标签和列轴标签为成员的列表
df.T # 行和列转置

2.概览

df.head(10) # 显示头部10⾏,默认5个
df.tail(10) # 显示末尾10⾏,默认5个
df.describe() # 查看数值型列的汇总统计,计数、平均值、标准差、最⼩值、四分位数、最⼤值 includ=”object” 查看字符串类型, includ =”all” 查看所有的

df.info() # 查看列索引、数据类型、⾮空计数和内存信息

`python
data = {‘name’: [‘John’, ‘Mike’, ‘Mozla’, ‘Rose’, ‘David’, ‘Marry’, ‘Wansi’, ‘Sidy’, ‘Jack’, ‘Alic’],
‘age’: [20, 32, 29, np.nan, 15, 28, 21, 30, 37, 25],
‘gender’: [0, 0, 1, 1, 0, 1, 0, 0, 1, 1],
‘isMarried’: [‘yes’, ‘yes’, ‘no’, ‘yes’, ‘no’, ‘no’, ‘no’, ‘yes’, ‘no’, ‘no’]}
label = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’]
data = pd.DataFrame(data,index=label)
print(data.dtypes)
print(data.index)
print(data.columns)
print(data.values)
print(data.size)
print(data.ndim)
print(data.empty)
print(data.axes)
print(‘——head———-‘)
print(data.head())
print(‘——tail———-‘)
print(data.tail())
print(‘——describe———-‘)
print(data.describe())
print(‘——info———-‘)
print(data.info())

out:
name object
age float64
gender int64
isMarried object
dtype: object
Index([‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’], dtype=’object’)
Index([‘name’, ‘age’, ‘gender’, ‘isMarried’], dtype=’object’)
[[‘John’ 20.0 0 ‘yes’]
[‘Mike’ 32.0 0 ‘yes’]
[‘Mozla’ 29.0 1 ‘no’]
[‘Rose’ nan 1 ‘yes’]
[‘David’ 15.0 0 ‘no’]
[‘Marry’ 28.0 1 ‘no’]
[‘Wansi’ 21.0 0 ‘no’]
[‘Sidy’ 30.0 0 ‘yes’]
[‘Jack’ 37.0 1 ‘no’]
[‘Alic’ 25.0 1 ‘no’]]
40
2
False
[Index([‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’], dtype=’object’), Index([‘name’, ‘age’, ‘gender’, ‘isMarried’], dtype=’object’)]
name age gender isMarried
f Marry 28.0 1 no
g Wansi 21.0 0 no
h Sidy 30.0 0 yes
i Jack 37.0 1 no
j Alic 25.0 1 no

Index: 10 entries, a to j
Data columns (total 4 columns):
# Column Non-Null Count Dtype

Original: https://blog.csdn.net/m0_63808770/article/details/125694721
Author: m0_63808770
Title: pandas查看属性和数据

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/738797/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球