数据科学库--第四天
pandas的常用数据类型
pandas是基于numpy数组构建的,但二者最大的不同是pandas是专门为处理表格和混杂数据设计的,比较契合统计分析中的表结构,而numpy更适合处理统一的数值数组数据。pandas数组结构有一维Series和二维DataFrame。
1.Series 一维,带标签数组
2.DataFrame 二维,Series容器
创建一个Series
例一:
import pandas as pd
t = pd.Series([1, 2, 31, 12, 3, 4])
print(t)
print("指定索引后:\n")
t2 = pd.Series([1, 2, 31, 12, 3, 4], index=list("abcdef"))
print(t2)
输出:
0 1
1 2
2 31
3 12
4 3
5 4
dtype: int64
指定索引后:
a 1
b 2
c 31
d 12
e 3
f 4
dtype: int64
例二:
import pandas as pd
dict_example = {
"name": "张三", "age": 88, "nickname": "法外狂徒"}
t =<