如何将系列的索引设置为行号?
How to set the index of a Series to the row number?
假设我有一个 Series
,
s = Series(range(10))
a = s[s % 2 == 0]
然后a
会像
0 0
2 2
4 4
6 6
8 8
我要做的是将a
的索引设置为行号,即
0 0
1 2
2 4
3 6
4 8
那怎么实现呢?
使用reset_index
a = s[s % 2 == 0].reset_index(drop=True)
假设我有一个 Series
,
s = Series(range(10))
a = s[s % 2 == 0]
然后a
会像
0 0
2 2
4 4
6 6
8 8
我要做的是将a
的索引设置为行号,即
0 0
1 2
2 4
3 6
4 8
那怎么实现呢?
使用reset_index
a = s[s % 2 == 0].reset_index(drop=True)