Home > Mobile >  removing just one of double indexes
removing just one of double indexes

Time:03-04

Is given a pandas.core.series.Series consisting of two pandas.core.series.Series:

S1 = pd.concat([S,S])
e.g.:|index| value    |
     | --- | -------- |
     |4707 | 25.408939|
     |13292| 24.288939|
     |38063| 22.766040|
     |39458|-16.478080|
     |39571|-15.085605|
     **|4707 | 25.408939|**
     |13292| 24.288939|
     |38063| 22.766040|
     |39458|-16.478080|
     |39571|-15.085605| 

where repeated indexes are repeated intentionally. I can't figure out, how can I delete just one of those repeated rows, for example row in bold.

extra info:

print(type(S1))
<class 'pandas.core.series.Series'>

print(type(S1[S1.index[i]]))
<class 'pandas.core.series.Series'>

CodePudding user response:

Use boolean indexing with | for bitwise OR with mask by Index.duplicated with inverting by ~ and test not match value 4707:

S2 = S1[~S1.index.duplicated() | (S1.index != 4707)]

print (S2)
4707   25.408939
13292  24.288939
38063  22.766040
39458 -16.478080
39571 -15.085605
13292  24.288939
38063  22.766040
39458 -16.478080
39571 -15.085605

Or simply remove value in pd.concat:

S1 = pd.concat([S,S.drop(4707)])
  • Related