赞
踩
https://blog.csdn.net/weixin_39778570/article/details/81157884
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
# 创建一个Series对象
s1 = Series([1,2,3,4], index=['A','B','C','D'])
s1
Out[51]:
A 1
B 2
C 3
D 4
dtype: int64
# Series的reindex操作
s1.reindex(index=['A','B','C','D','E'])
Out[53]:
A 1.0
B 2.0
C 3.0
D 4.0
E NaN
dtype: float64
# 缺失值填充
s1.reindex(index=['A','B','C','D','E'], fill_value=10)
Out[54]:
A 1
B 2
C 3
D 4
E 10
dtype: int64
# 创建一个Series对象s2
s2 = Series(['A','B','C'], index=[1,5,10])
s2
Out[57]:
1 A
5 B
10 C
dtype: object
# reindex
s2.reindex(index=range(15))
Out[58]:
0 NaN
1 A
2 NaN
3 NaN
4 NaN
5 B
6 NaN
7 NaN
8 NaN
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。