Pandas数据结构之Series

import pandas as pd
#Series类
#生成series类的方法:1.
obj = pd.Series([4, 7, -5, 3])
obj2 = pd.Series([4, 7, 5, -3], index=['a', 'b', 'c', 'd'])
print(obj2.values, obj2.index)
print(obj2['a'])
print(obj2[['c', 'a', 'd']]) #必须要加两层中括号
print(obj[obj > 0])
print(obj2[obj2 > 0])


#2.直接使用字典生成series
sdata = {'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000, 'Utah': 5000}
obj3 = pd.Series(sdata)
print(obj3)
states = ['California', 'Ohio', 'Oregon', 'Texas']
obj4 = pd.Series(sdata, index=states)
print(obj4)
#NAN标记缺失值的方式
print(obj4.isnull())
print(obj4.notnull())
print(obj3+obj4)#相当于数据库中的join操作

#给series对象及其索引进行命名
obj4.name = 'population'
obj4.index.name = 'state'
print(obj4)
obj.index = ['Bob', 'Steve', 'Jeff', 'Ryan']
print(obj)
[ 4  7  5 -3] Index(['a', 'b', 'c', 'd'], dtype='object')
4
c    5
a    4
d   -3
dtype: int64
0    4
1    7
3    3
dtype: int64
a    4
b    7
c    5
dtype: int64
Ohio      35000
Oregon    16000
Texas     71000
Utah       5000
dtype: int64
California        NaN
Ohio          35000.0
Oregon        16000.0
Texas         71000.0
dtype: float64
California     True
Ohio          False
Oregon        False
Texas         False
dtype: bool
California    False
Ohio           True
Oregon         True
Texas          True
dtype: bool
California         NaN
Ohio           70000.0
Oregon         32000.0
Texas         142000.0
Utah               NaN
dtype: float64
state
California        NaN
Ohio          35000.0
Oregon        16000.0
Texas         71000.0
Name: population, dtype: float64
Bob      4
Steve    7
Jeff    -5
Ryan     3
dtype: int64

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值