当前位置:   article > 正文

Pandas入门系列(六) -- reindex_cannot reindex a non-unique index with a method or

cannot reindex a non-unique index with a method or limit

数据分析汇总学习

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/982012
推荐阅读
相关标签
  

闽ICP备14008679号