如何更改熊猫系列中的个人价值?

时间:2020-11-07 15:05:07

标签: python pandas

import pandas as pd
test_df = pd.Series([0,0,0,1,1,1,1,0,1,1,1,1])
test_df[0] = 1 

如何将本系列的第一个值更改为一个?它不像列表那样起作用。我尝试使用.replace方法,但我只想更改一个值,而不是所有值。

1 个答案:

答案 0 :(得分:0)

尝试使用loc

test_df.loc[0] = 1 
test_df
Out[140]: 
0     1
1     0
2     0
3     1
4     1
5     1
6     1
7     0
8     1
9     1
10    1
11    1
dtype: int64