import numpy as np import pandas as pd # 从python list创建 series = pd.Series([1, 2, 3]) print(series) # [1 2 3] # 从python tuple创建 series = pd.Series((1, 2, 3)) print(series) # [1 2 3] # 从python dictionary创建 series = pd.Series({"one": 1, "two": 2, "three": 3}) print(series) # 0 1 # 1 2 # 2 3 # dtype: int64 # 从numpy数组创建 array = np.array([1, 2, 3]) series = pd.Series(array) print(series) # 0 1 # 1 2 # 2 3 # dtype: int32 # 获取索引 print(series.index) # RangeIndex(start=0, stop=3, step=1) # 获取值 print(series.values) # [1 2 3] # 创建Series时直接指定索引 series = pd.Series([1, 2, 3], index=["one", "two", "three"]) print(series) # one 1 # two 2 # three 3 # dtype: int64 # 修改索引 series.index = ["index1", "index2", "index3"] print(series) # index1 1 # index2 2 # index3 3 # dtype: int64