python的坑

【python】dataframe操作手册

2019-10-14  本文已影响0人  MichalLiu

1.连接数据框

import pandas as pd
 # 读取excel的sheet
df_1 = pd.read_excel(r'C:\Users\Dell\Desktop\名单\MARS_类型1.xlsx',sheet_name = 'Sheet1')
df_2 = pd.read_excel(r'C:\Users\Dell\Desktop\名单\拒绝.xlsx',sheet_name = 'Sheet1') 
# 左连接两张sheet 
df_3 = df_1.join(df_2.set_index('id_card'),on='idcard_no',how='left') 
# 限制字段条件
df_4 = df_3[(df_3['is_pass'].astype(float) != 0)]                                      
writer = pd.ExcelWriter(r'C:\Users\Dell\Desktop\MARS_类型1.xlsx') 
 # 将结果写入新的excel 
df_4.to_excel(writer, sheet_name='Sheet1',index=False)   
writer.save()
上一篇 下一篇

猜你喜欢

热点阅读