首页 > > 详细

讲解Python设计、Python讲解、调试Python语言程序

# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
nan=np.nan
nan11=[nan]*11
nan7=[nan]*7
header=['?:Global',nan,nan,nan,nan,nan,'?:GlobalNU',nan,nan,nan,nan]
header0=['Date','Geo','DNU','DLU',nan,nan,'Date','organic','buy','theme2kika','others']
header1=['Date','organic','buy','theme2kika','others',nan,'Date','organic','buy','theme2kika','others']
header2=['Date','US','ID','BR','MX',nan,'Date','US','ID','BR','MS']
column=['Date','organic','buy','theme2kika','others']
pathone=r'Data+of+User+Growth+-+raw+data+by+global+(1).csv'
pathtwo=r'Data+of+User+Growth+-+raw+data.csv'
paththree=r'Data+of+User+Growth+-+raw+data+with+agency.csv'
outpath='result.csv'
table0=pd.DataFrame([header0])
table0.index=[2]
table0.columns=['Date','organic','buy','theme2kika','others','nan7','Date','organic','buy','theme2kika','others']
data_one=pd.read_csv(pathone)
table2=data_one.replace('_?,np.nan).dropna().tail(7)
table2.index=range(3,10)
table2.columns=['Date','organic','buy','theme2kika','others']
data_two=pd.read_csv(pathtwo)
data_two1=data_two.iloc[:,0:4]
data_two1=data_two1.replace(0,np.nan).dropna().tail(7)
data_two1.index=range(3,10)
table1=pd.concat([data_two1[['Date','geo']],data_two1[['dnu','dlu']]],axis=1)
table1.columns=['Date','organic','buy','theme2kika']
table1['others']=nan7
table1['nan7']=nan7
table12=pd.concat([table1,table2],axis=1)
table12.loc[10]=nan11
table12.loc[11]=nan11
table12.loc[12]=['?:DNU',nan,nan,nan,nan,nan,'?:DLU',nan,nan,nan,nan]
table12.loc[13]=header2
data_two21=data_two.iloc[:,[5,6]]
data_two22=data_two.iloc[:,[10,11]]
data_two23=data_two.iloc[:,[15,16]]
data_two24=data_two.iloc[:,[20,21]]
data_two2=pd.concat([data_two21,data_two22,data_two23,data_two24],axis=1)
table3=data_two2.drop(['Date.2','Date.3','Date.4'],axis=1).replace(0,np.nan).dropna().tail(7)
table3.index=range(14,21)
table3.columns=column
table3['nan7']=nan7
data_two31=data_two.iloc[:,[5,7]]
data_two32=data_two.iloc[:,[10,12]]
data_two33=data_two.iloc[:,[15,17]]
data_two34=data_two.iloc[:,[20,22]]
data_two3=pd.concat([data_two31,data_two32,data_two33,data_two34],axis=1)
table4=data_two3.drop(['Date.2','Date.3','Date.4'],axis=1).replace(0,np.nan).dropna().tail(7)
table4.index=table3.index
table4.columns=column
table34=pd.concat([table3,table4],axis=1)
table34.loc[21]=nan11
table34.loc[22]=['?:usnu',nan,nan,nan,nan,nan,'?:idnu',nan,nan,nan,nan]
table34.loc[23]=header1
data_three=pd.read_csv(paththree)
data_three=data_three.dropna(axis=1).dropna().tail(7)
table5=data_three.iloc[:,0:5]
table5.index=range(24,31)
table5.columns=column
table5['nan7']=nan7
table6=data_three.iloc[:,10:15]
table6.index=table5.index
table6.columns=column
table56=pd.concat([table5,table6],axis=1)
table56.loc[31]=nan11
table56.loc[32]=nan11
table56.loc[32,'Date']='table56.loc[32,'Date']='table56.loc[33]=header1
table7=data_three.iloc[:,5:10]
table7.index=range(34,41)
table7['nan7']=nan7
table7.columns=table5.columns
table8=data_three.iloc[:,15:20]
table8.columns=column
table8.index=table7.index
table78=pd.concat([table7,table8],axis=1)
table=pd.concat([table0,table12,table34,table56,table78])
table.columns=header
table.to_csv(outpath,index=False)

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!