【第5章】1、pandas入门(Dict、Serise、DataFrame)

这篇笔记介绍了Pandas的基础操作,包括如何从字典创建Series和DataFrame,转换序列和矩阵,以及对序列和DataFrame的各种操作,如索引查询、修改值、添加行列等。此外,还展示了字典、序列和DataFrame之间的转换关系。
摘要由CSDN通过智能技术生成

笔记来源: pandas官网书籍

1、Dict(字典)

  • (1)、简单的字典,有键(key)和值(value):dict={‘key’:value,‘key’:value}
simple_dict={
   'a':1,'b':2,'c':3}
  • (2)、复杂的字典(字典嵌套字典):dict={‘key’:{‘key’:value}}
complie_dict={
   'a':{
   'b':2,'c':3},'d':{
   'e':4,'f':5}}
  • (3)、字典转为序列:obj=pd.Series(dict)
 import pandas as pd
# 转为序列
pd.Series(simple_dict)
"""
a    1
b    2
c    3
dtype: int64
"""
# 指定索引
pd.Series(simple_dict,index=['a','c','b'])
"""
a    1
c    3
b    2
dtype: int64
"""
  • (4)、字典转为矩阵:frame=pd.DataFrame(dict)
# 转为矩阵
pd.DataFrame(complie_dict)
"""
	a	d
b	2.0	NaN
c	3.0	NaN
e	NaN	4.0
f	NaN	5.0
"""

2、Serise(序列)

  • (1)、一般的序列:pd.Serise([values],index=[indexs]),一维数组,有值(value)和索引(index)
# 设置值
pd.Series([1, 2, 3, 4])
"""
0    1
1    2
2    3
3    4
dtype: int64
"""
# 设置值和索引
pd.Series([1, 2, 3, 4],index=['a','b','c','d'])
"""
a    1
b    2
c    3
d    4
dtype: int64
"""
  • (2)、获取序列的值和索引:obj.index/values
obj=pd.Series([1,2,3,4
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasmine_qiqi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值