python替代excel函数处理数据

vs00ASPNET 2020-03-03

import pandas as pd import numpy as np import csv,datetime def mjdfb(x): if x<120: return ‘90-120方‘ elif x<140: return ‘120-140方‘ return ‘140方以上‘ def yszzt(x): if int(x)==0: return ‘未取证‘ elif int(x)<int(‘43890‘): return ‘已取证‘ return ‘未取证‘ def rgzt(x): if int(x)==0: return ‘未认购‘ elif int(x)>int(‘43890‘): return ‘未认购‘ return ‘已认购‘ def qyzt(x): if int(x)==0: return ‘未签约‘ elif int(x)>int(‘43890‘): return ‘未签约‘ return ‘已签约‘ def wqzt(x): if int(x)==0: return ‘未网签‘ elif int(x)>int(‘43890‘): return ‘未网签‘ return ‘已网签‘ if __name__==‘__main__‘: csv_file=open(‘房源清单处理.csv‘,‘w+‘,newline=‘‘,encoding=‘utf-8‘) writer=csv.writer(csv_file) fileName=r‘/Users/Desktop/python/python生成现金流套表/房源清单.csv‘ df=pd.read_csv(fileName) df[‘面积段分布‘]=df.预测建筑面积.apply(mjdfb) df[‘预售证状态‘]=df.预售许可证取证日期.apply(yszzt) df[‘认购状态‘]=df.认购日期.apply(rgzt) df[‘签约状态‘]=df.签约日期.apply(qyzt) df[‘网签状态‘]=df.网签日期.apply(wqzt) df[‘已取证未认购‘]=df[‘预售证状态‘]+df[‘认购状态‘] df[‘已认购未签约‘]=df[‘认购状态‘]+df[‘签约状态‘] df[‘已签约未网签‘]=df[‘签约状态‘]+df[‘网签状态‘] # print(‘2020/1/1‘-datetime.date.today()) df.to_csv(csv_file)

相关推荐