科学计算库Pandas(1):创建Series与DataFrame对象

科学计算库Pandas(1):创建Series与DataFrame对象

Pandas使用两种数据类型:Series与dataframe

1.Series对象

import pandas as pd
from pandas import Series,DataFrame
import numpy as np
1.1创建
#创建Series对象,没有自定义索引,类似一维数组
se1 = Series([1,2,3,4])
#创建Series对象,自定义了索引
se2 = Series(data=[1,2,3,4],index=['a','b','c','d'])
se3 = Series(data=[5,6,7,8],index=list('fine'))

print(se1)
print(se2)
print(se3)
0    1
1    2
2    3
3    4
dtype: int64
a    1
b    2
c    3
d    4
dtype: int64
f    5
i    6
n    7
e    8
dtype: int64
1.2获取数据
print(se2.values)#获取内容
print(se2.index)#获取索引
print(list(se2.iteritems()))#获取索引和值对
[1 2 3 4]
Index(['a', 'b', 'c', 'd'], dtype='object')
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
#Series对象支持位置和标签两种方式获取数据
print('索引下标',se2['c'])#索引‘c’对应数字3
print('位置下标',se2[2])#下标‘2’对应数字3
索引下标 3
位置下标 3
#获取不连续的数据,输入用[]阔起来
print(se2[
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值