О данных Excel: первая строка содержит заголовки столбцов, а индексы отсутствуют.
Знаете ли вы, что не так с моим кодом?
Вы также можете предложить улучшения
Код: Выделить всё
import pandas as pd
import numpy as np
table1_data = r'C:\Users\--->file1.xlsx'
table2_data = r'C:\Users\--->file2.xlsx' # this is always new data
database_data = r'C:\Users\--->file3xlsx'
table1 = pd.read_excel(table1_data, header=0, index_col=None,keep_default_na=True)
table2 = pd.read_excel(table2_data, header=0, index_col=None,keep_default_na=True)
database = pd.read_excel(database_data, header=0, index_col=None,keep_default_na=True)
sold = table1[~table1.License.isin(table2.License)]
sold['Deleted'] = table2.loc[1,'Deleted']
database = pd.concat([database, sold])
s = sold.set_index('License')['Deleted']
table1['Deleted'] = table1['License'].map(s).fillna(table1['Deleted']).astype('datetime64[ns]')
cond = table1['License'].isin(sold['License'])
table1.drop(table1[cond].index, inplace = True)
bought = table2[~table2.License.isin(table1.License)]
bought['Deleted'] = ''
table1 = pd.concat([table1,bought])
database.to_excel(r'C:\Users\--->file3.xlsx')
table1.to_excel(r'C:\Users\--->file1.xlsx')
Подробнее здесь: https://stackoverflow.com/questions/637 ... ex-columns
Мобильная версия