Use pandas to automate office filling

Use pandas to automate office filling

Due to a certain job requirement, it is necessary to improve a table of road information. Specifically, based on a known information table with many points of latitude and longitude, another road table needs to be supplemented with the latitude and longitude information of the start point and end point according to the numbers of the start point and end point. Before They are all copied manually, but due to the needs of the project, these points always need to be changed. Finally, I wrote a program to help me fill in the form. I didn’t expect it to be very simple. A for loop will get it done, hahaha

The known table is as follows:
insert image description here
insert image description here
try to write the program as follows:

import pandas as pd
df_info = pd.read_excel('道路信息.xlsx',sheet_name= 'Sheet2')
df = pd.read_excel('道路信息.xlsx',sheet_name= 'Sheet1')
for i in range(len(df)):
    df['起点经度'][i] = df_info[df_info['id'] == df['起点编号'][i]]['x']
    df['起点纬度'][i] = df_info[df_info['id'] == df['起点编号'][i]]['y']
    df['终点经度'][i] = df_info[df_info['id'] == df['终点编号'][i]]['x']
    df['终点纬度'][i] = df_info[df_info['id'] == df['终点编号'][i]]['y']
df.to_excel('道路信息_new.xlsx',index=None)

The final result is as follows:
insert image description here
Fill in successfully! ! !

Guess you like

Origin blog.csdn.net/weixin_43697614/article/details/125228251