开发者学堂课程【Python 常用数据科学库:对象操作1】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/546/detail/7482
对象操作1
内容介绍
一、对象的增删改查
二、Series 结构的查操作
三、Series 结构的改操作
四、Series 结构的增操作
一、对象的增删改查
In [1]:import pandas as pd
In [2]: data = [10, 11,12]
index = ['a','b','c']
s = pd. Series (data = data, index = index)
S
二、Series 结构的查操作
In [4]:s[0]
In [5]:s[0:2]
In [7]: mask = [True, False, True]
s [mask]
//指定找值
In [8]:s.loc['b']
//根据位置找值
In [9]:s.iloc[1]
三、Series 结构的改操作
//修改值
In [10]:s1 = s.copy()
s1['a']= 100
s1
//不会在原始位置进行修改,可以用这样
In [11]: s1. replace (to replace = 100, value = 101, inplace = False)
//会在原始位置进行修改,可以用这样
In [11]: s1. replace (to replace = 100, value = 101, inplace = True)
//修改索引
In [17]: s1. index = ['a','b','d']
s1
//指定索引进行修改(单独修改某一个索引)
In [18]: s1. rename (index = {'a':'A'], inplace = True)
s1
四、Series 结构的增操作
In [30]:data = [100, 110]
index = ['h','k']
s2 = pd. Series (data = data, index = index)
s2
In [33]:s1.append (s2)
//再增加一行
In [36]: s3 = s1.append (s2)
In [37]:s3['j'] = 500
s3
//保留原来索引
In [38]: s1. append (s2, ignore_index = False)
//不保留原来索引,按照新的索引方式排序
In [39]: s1. append (s2, ignore_index = True)