Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在excel工作表中创建具有相应值的新列_Python_Excel_Pandas_Dataframe - Fatal编程技术网

Python 如何在excel工作表中创建具有相应值的新列

Python 如何在excel工作表中创建具有相应值的新列,python,excel,pandas,dataframe,Python,Excel,Pandas,Dataframe,我有一张excel表格 还有一个像这样的 我想根据产品id在第一页添加通道id,如下所示 我需要帮助,最好使用python数据帧或sql server来完成此操作,请使用pandas read_excel模块,如下所示: 我已经删除了第一个数据帧中的“过道id”列,因为它没有定义,可能会导致冲突 import pandas as pd input_file1 = 'sales_table.xlsx' input_file2 = 'sales_table2.xlsx' df1 = pd.

我有一张excel表格

还有一个像这样的

我想根据产品id在第一页添加通道id,如下所示


我需要帮助,最好使用python数据帧或sql server来完成此操作,请使用pandas read_excel模块,如下所示: 我已经删除了第一个数据帧中的“过道id”列,因为它没有定义,可能会导致冲突

import pandas as pd

input_file1 = 'sales_table.xlsx'
input_file2 = 'sales_table2.xlsx'

df1 = pd.read_excel(input_file1)
df1 = df1[['order_id', 'product_id', 'add_to_cart_order', 'reordered']]
df2 = pd.read_excel(input_file2)

pd.merge(df1, df2)

默认情况下,这将创建一个合并在公共列上的新数据框。

无图像,添加文本数据在第1页产品标识为5位数字值,但在第2页中,较小的值在连续或不同集合中!!非常感谢。这工作做得很好。投赞成票!把它标为正确答案@穆罕默德