python 基础知识 Pandas库

这篇博客介绍了Pandas库的基础知识,包括Series和DataFrame的数据结构,以及如何进行数据操作,如使用.reindex()重排索引,.drop()删除行或列,还有算术和比较运算等。
摘要由CSDN通过智能技术生成

Pandas 扩展数据类型 关注数据应用表达 数据与索引之间的关系

Series 数据与索引组成

import pandas as pd
a=pd.Series([9,8,7,6])
0    9
1    8
2    7
3    6
dtype: int64  //numpy中的数据类型

a=pd.Series([9,8,7,6],index=['a','b','c','d'])
a    9
b    8
c    7
d    6
dtype: int64

创建Series

import pandas as pd
//标量值
s=pd.Series(25,index==['a','b','c','d'])
//字典类型
d=pd.Series({
   'a':9,'b':8,'c':7,})
a    9
b    8
c    7
dtype: int64
e=pd.Series({
   'a':9,'b':8,'c':7,},index=['c','a','b','d']) 
从字典中进行选择操作
c    7.0
a    9.0
b    8.0
d    NaN
dtype: float64
//ndarray类型创建
n=pd.Series(np.arange(5))
n=pd.Series(np.arange(5),index=np.arange(9,4,-1))

Series基本操作

import pandas as pd
b.index
Int64Index([9, 8, 7, 6, 5], dtype='int64')
b.values 

b[1]
b['b']  //自动索引和自定义索引并存
b[['c',
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值