Help us understand the problem. What is going on with this article?

PandasのDataFrameの要素を列名指定で更新する

目的

DataFrameの要素を列名指定で更新したい

環境

OS: ubuntu18.04
pythonバージョン: 3.6.9

ソースコード

main.py
#!/usr/bin/env python3
import pandas as pd

if __name__ == '__main__':
    dic = {'key1':[1,2,3],'key2':[4,5,6],'key3':[7,8,9]}

    df = pd.DataFrame.from_dict(dic)

    print(df)

    df.iloc[-1, df.columns.get_loc('key2')] = 10 #末尾行のKey2の値を更新

    print(df)

結果

   key1  key2  key3
0     1     4     7
1     2     5     8
2     3     6     9

   key1  key2  key3
0     1     4     7
1     2     5     8
2     3    10     9
YGocho
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away