python - 替换数据框中的定位值

标签 python pandas

我有以下 df:

    A  B  C 
0   s  d  f
1   3  5  3 
2   4  4  5
3   6  6  6

我想将 df.iloc[[0],[0]] 处的值从 s 替换为 j 。我怎样才能这样做?

最佳答案

将位置索引器传递给 iat:

df.iat[0, 0] = 'j'

或者,将标签传递给at:

df.at[0, 'A'] = 'j'

df

   A  B  C
0  j  d  f
1  3  5  3
2  4  4  5
3  6  6  6

关于python - 替换数据框中的定位值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49287830/

相关文章:

Python Pandas : How to subtract values in two non-consecutive rows in a specific column of a dataframe from one another

python Pandas : diff between 2 dates in a groupby

python - 合并多个 CSV 文件并按字段删除重复项

python - pandas 替换列子集的空值

python - 避免在新的 python 字符串格式中舍入

python - Postgresql ON CONFLICT 在 sqlalchemy 中

python - python 映射中的派生值

python - Matlab Engine Python - OSx Anaconda Segfault 或 iPython 的 DYLD_LIBRARY_PATH 错误

python - 在多索引中扩展日期时间索引

python - 查找拼字板上的所有单词