columns指定列名
c = pd.DataFrame(
[[5, 6, 2, 3],
[8, 4, 6, 3],
[6, 4, 31, 2]],
columns=['one', 'two', 'three', 'four']
)
通过字典的形式创建df
# 使用字典创建
d = pd.DataFrame({
# 列名:值
'one': 4, # 自动填充 [4, 4, 4]
'two': [6, 2, 3], # 多个行
'three': list(str(982)), # [9. 8, 2]
})
取前几行数据
head取前5行
# d.head头部数据,默认前5行
print(d.head)
head(n)取前n行
# 取指定的前几行d.head(n)
print(d.head(2))
取尾部数据
# 取尾部数据 tail,默认后5行
print(d.tail())
print(d.tail(2)
describe
count 元素个数统计
mean 列的平均数
std 标准差
min 列的最小值
25% 分位数
50% 分位数
75% 分位数
max 列的最大值
print(d.describe())
转置T
将行变成列,将列变成行
print(d.T)
# result
0 1 2
one 4 4 4
two 6 2 3
three 9 8 2