python dataframe 按照索引和列名 操作


    dd = pd.DataFrame({"1":[1,2,3], "2":[20,30,40]})

    print(dd)

    for index, row in dd.iterrows():
        val = row["1"]
        dd.iloc[index]["2"] = val * 100

    print("---------------------------")
    print(dd)

结果:

   1   2
0  1  20
1  2  30
2  3  40
---------------------------
   1    2
0  1  100
1  2  200
2  3  300

发布了42 篇原创文章 · 获赞 35 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/wang603603/article/details/87617513