I want to update the elements of DataFrame by specifying the column name
OS: ubuntu18.04 python version: 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 #Update the value of Key2 in the last line
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
Recommended Posts