The problem I'm having is processing a table in the database and then merging all to write to another table.
The table structure is like this:
Owns 3 database tables.
I want to merge into the table by the Entryid
My idea is to extract the data with pandas and process.
But there are many problems writing to the database.
Below is the code I tried:
# -*- coding: UTF-8 -*-
import pandas as pd
import pymongo
def data_Process():
client = pymongo.MongoClient(host="mongodb://localhost:27017/")
collection1 = client.test.declare_customs
collection2 = client.test.tax
collection3 = client.test.ship
collection4 = client.test.jieguan
data1 = pd.DataFrame(list(collection1.find()))
data2 = pd.DataFrame(list(collection2.find()))
data3 = pd.DataFrame(list(collection3.find()))
data3 = data3.groupby(by=['entryId']).agg(';'.join)
data4 = pd.merge(data1, data2, on='entryId', how='left')
data5 = pd.merge(data4, data3, on='entryId', how='left')
data5.to_excel('data5.xlsx')
collection4.insert(data5)
if __name__ == '__main__':
data_Process()
If you have a better idea.
Thanks.