Pandas 导入模组

import pandas as pd

Pandas 创建 Series

# 创建一个Series
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser)

Pandas 自定义 Index 创建一个 Series

# 创建一个Series带自定义Index
ser = pd.Series(["red", "yellow", "blue", "green"], index=['a', 'b', 'c', 'd'])
print(ser)

Pandas 获取一个 Series 的 Index

# 获取一个Series的Index
ser = pd.Series(["red", "yellow", "blue", "green"], index=['a', 'b', 'c', 'd'])
print(ser.index)

Pandas 获取一个 Series 的长度

# 获取一个Series的长度
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser.size)

Pandas 获取 Series 的资料

# 查看Series资料
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser.describe())

Pandas 统计值在 Series 出现的次数

# 查找值在Series出现的次数
ser = pd.Series(["red", "red", "yellow", "blue", "green"])
print(ser.value_counts())

Pandas 查看 Series 的维度

# 查看Series维度
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser.ndim) # 默认都是 1 维

Pandas 在 Series 中取值

# Series取值
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser[1]) # 输出 yellow

Pandas 切片 Series 输出

# Series 切片
ser = pd.Series(["red", "yellow", "blue", "green"])
print(ser[1:])