python用其他文件替换列值

时间:2021-03-29 15:37:14

标签: python pandas

#导入熊猫模块

    import pandas as pd

#读取要合并/或替换的文件

     file1 = pandas.read_excel ("file1 name.xlsx")

     file2 = pandas.read_excel ("file2 name.xlsx")

#1。指示我想用 ex 替换的列标题)有两列“column1”、“column2”

    columns_replace = ["column1", "column2"]

#2。需要删除我要替换的列中的值

    file2.drop(columns_replace, axis = "columns", inplace= true)

#3。替换我想覆盖的值

    file2[columns_replace] = file1[columns_replace]

问题: 如何替换两个文件中相同列名中的值?

我希望文件 2 在相同的列名下与文件 1 具有相同的值。

0 个答案:

没有答案
相关问题