python 创建Series

#Pandas特有的数据类型
#创建Series

#用于存储一行或一列的数据,以及与之相关的索引的集合
import pandas as pd

s1 = pd.Series([43,56])
print(s1)

s2 = pd.Series([43,12.4])
print(s2)

s3 = pd.Series([False,True])
print(s3)

#有一个是对象,整个都变成对象
s4 = pd.Series([44,23.1,True,'Hello World'])
print(s4)
# 0             44
# 1           23.1
# 2           True
# 3    Hello World
# dtype: object

#改变第1列的索引(默认是数字)
ss = pd.Series(['Bill Gates','微软创始人'],index = ['Person','Who'])
print(ss)
# Person    Bill Gates
# Who            微软创始人
# dtype: object

x = pd.Series(['a','True',1],index = ['first','second','third'])
#追加值是2
n = pd.Series(['2'])
x =x.append(n)
print(x)
# first        a
# second    True
# third        1
# 0            2

#根据位置(索引)删除,返回新的序列
#print(x.drop(x.index[3]))


你可能感兴趣的:(Python)