python替代excel函數處理數據

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)
相關文章
相關標籤/搜索