This is the first use python It's a practical project , If there is something wrong , Please correct me !

<> target :

use python Put the table 1 Insert the corresponding data in the table 2, realization excel In vlookup function

<> preparation :

a. numpy library ,pandas library ( Environment building is really important )

b. A table that needs to be filled with data

c. Existing data table

Results display :

<> Operation steps

step 1: Read the contents of two tables
import pandas as pd # Regional information table df_location = pd.read_excel(
"D:\python\\numpy\\test1\ Regional information table .xlsx" ) df_location.head() # Database export table df_number =
pd.read_excel("D:\python\\numpy\\test1\ Data collection table .xlsx") df_number.head()
( Don't put files on the desktop , Don't ask me why ,QAQ)

step 2: You only need to use some of the columns in the table
# Only a few columns of the second table are filtered ( Select only the urban areas and users in Table 2 ) df_number = df_number[[ " urban district ", " Number of users "]] df_number.
head()
step 3: realization vlookup The most important step in a function – Determine whether the data in two tables match
df_merge = pd.merge(left=df_location, right=df_number, left_on=" urban district ", right_on=
" urban district ") df_merge.head()
step 4: Merged exported data table
df_merge.to_excel("d:\\python\\numpy\\test1\\ Merged data table .xlsx", index=False)
That's all , Do not understand or feel that there are problems to improve , Welcome to leave a message below . I am also Xiaobai , Writing for the first time , I hope you can support me !

Technology