5.1 pandas的数据结构介绍
pandas有两个数据结构:Series 和 DataFrame
Series
Series是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及 一组与之相关的数据标签(即索引)组成。
Series的字符串表现形式为: 索引在左边,值在右边。.values返回值,.index返回索引值
obj = pd.Series([4, 7, -5, 3])
>> obj
>0 4
1 7
2 -5
3 3
dtype: int64
自定义数据点标记索引:
obj2 = pd.Series([4, 7, -5, 3], index=['d', 'b', 'a', ' c'])
>> obj
>d 4
b 7
a -5
c 3
dtype: int64
pd.Series(arg,Index=None) 可直接把字典转换成Series。可通过一个拍好顺序的键值列表,改变字典转换成Series后的顺序。
sdata = {
'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000 , 'Utah': 5000}
states =