import requests
import pandas as pd
from datetime import date
today=str(date.today())
filepath='/Users/kangyongqing/Documents/kangyq/202206/季度评级月数据支持/2023年薪改测算/ip地址判断/'
ipfile='01lastestipadress20230918.csv'
danganfile='20230918_174045.csv'
# def get_location(a):
#
# response=requests.get(f'https://ipapi.co/{a}/json').json()
# print(response)
# location_data={
# 'city':response.get('city'),
# 'region':response.get('region'),
# 'country':response.get('country')
# }
# return location_data
# b='222.249.231.150'
# print(get_locateion(b))
dt1=pd.read_csv(filepath+ipfile)
print(dt1.info)
dt2=pd.read_csv(filepath+danganfile)
dt3=pd.merge(dt2,dt1,on='教师id',how='left')
dt3['ip地址']=dt3['ip'].apply(lambda x:requests.get(f'https://ipapi.co/{x}/json').json().get('city'))
print(dt3.head())
dt3['教师id']=dt3['教师id'].astype(np.int64).astype(str)
dt3.to_excel(filepath+'教师ip档案'+today+'.xlsx',index=False)
print(dt3[dt3['ip地址'].isnull].count())
- ip地址取city
- ip地址可解析字段范围