pandas的Series源码解读

import numpy as np
import pandas as pd

# Series方法源码地址:https://github.com/pandas-dev/pandas/blob/master/pandas/core/series.py
# 共有5个参数 data index dtype name copy 看以下示例:

# # (1) 参数index
print("*"*30+"参数index"+"*"*10)
d = {'a': 1, 'b': 2, 'c': 3}
ser = pd.Series(data=d, index=['a', 'b', 'c'])
print(ser)
print()

d = {'a':1,'b':2,'c':3}
ser = pd.Series(data=d, index=['x','y','z'])
print(ser)
print()

# 参数copy
print("*"*30+"参数copy"+"*"*10)
r = [1, 2]
ser = pd.Series(r, copy=False)
ser.iloc[0] = 999
print(r) # [1, 2]
print(ser) # 0 999
# 1 2
print()

r = np.array([1, 2])
ser = pd.Series(r, copy=False)
ser.iloc[0] = 888
print(r) # [888 2]
print(ser) # 0 888
# 1 2

# 参数dtype name
print("*"*30+"参数dtype name"+"*"*10)

# 可以在调用构造函数时初始化Series名称
s = pd.Series([1, 2, 3],dtype=np.int64, name='Number')
print(s)

s.name = 'Integers' # 修改name
print(s)

# DataFrame中的Series的名称是它的列名
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
columns=["Odd Numbers", "Even Numbers"]) # DataFrame方法源码
print(df)
print(df["Even Numbers"].name) # Even Numbers ???

 

未完待续~~~

上一篇:Linux项目:文件传输


下一篇:【狂神说Java】实现多线程:Callable接口