相关疑难解决方法(0)

Pandas替换特定列上的值

我知道这两个类似的问题:

熊猫取代了价值观

Pandas:替换数据帧中的列值

我使用了一种不同的方法来替换值,我认为它应该是最干净的值.但它不起作用.我知道如何解决它,但我想理解为什么它不起作用:

In [108]: df=pd.DataFrame([[1, 2, 8],[3, 4, 8], [5, 1, 8]], columns=['A', 'B', 'C']) 

In [109]: df
Out[109]: 
   A  B  C
0  1  2  8
1  3  4  8
2  5  1  8

In [110]: df.loc[:, ['A', 'B']].replace([1, 3, 2], [3, 6, 7], inplace=True)

In [111]: df
Out[111]: 
   A  B  C
0  1  2  8
1  3  4  8
2  5  1  8

In [112]: df.loc[:, 'A'].replace([1, 3, 2], [3, 6, 7], inplace=True)

In [113]: df
Out[113]: …
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

pandas ×1

python ×1