"""
reindex:用于创建一个符合新索引的新对象
"""
import numpy as np
import pandas as pd
obj = pd.Series([1, 2, 3, 4], index=["One", "Two", "Three", "Four"])
print(obj)
# ▶知识点1:Series调用reindex方法时,会将数据按照新的索引进行排列,如果某个索引值之前并不存在,则会引入缺失值
obj_1 = obj.reindex(["One", "Three", "Two", "Four", "Five", "Six", "Two"])
print(obj_1)
"""
One 1.0
Three 3.0
Two 2.0
Four 4.0
Five NaN
Six NaN
Two 2.0
dtype: float64
"""
"""
reindex方法的参数:
参数 描述
---------------------------------------------------------------------------------------
index 新建作为索引的序列,可以是索引实例或任意其他序列型Python数据结构,
索引使用时无需复制
method 插值方式:ffill-向前填充,
二、Pandas-4.重建索引
最新推荐文章于 2024-06-17 14:55:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)