Pandas commonly used supplements

import os
import pandas as pd
from datetime import date
import time
today=str(date.today())
curdate=time.strftime('%Y-%m-%d',time.localtime())
curtime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
#格式化时间日期
# print(curdate)
# print(curtime)


downpath='/Users/kangyongqing/Downloads/'
lists=os.listdir(downpath)
print('未经处理的文件列表:\n %s'%lists)

lists.sort(key=lambda x:os.path.getmtime((downpath+x)) )
filenew=os.path.join(downpath,lists[-1])
print('时间排序后的文件列表:\n %s \n'%lists)
print('最新文件路径:\n%s'%filenew)

filename="文件%s"%curtime
# data=pd.read_csv(downpath+'20230526_105522.csv',dtype='object')
data=pd.read_csv(filenew,dtype='object')
data.to_excel(downpath+filename+'.xlsx',index=False)

print('现在时间是%s,任务已完成,请查收'%curtime)

Import files daily, add time & date to identify files, sort by file creation time under the path and get the latest files

import pandas as pd
import numpy as np
from datetime import date
today=str(date.today())


downpath='/Users/kangyongqing/Downloads/'
data=pd.read_csv(downpath+'20230526_105522.csv',dtype='object')
data1=data[['日期','学生姓名','班型','业绩归属','一级渠道','老师姓名','销售姓名','开始时间','是否完课','版本名称','level级别','lesson_id','是否转化','转化时间']]
data.to_excel(downpath+'试听课明细'+today+'.xlsx',index=False)
data1.to_excel(downpath+'试听课明细特定'+today+'.xlsx',index=False)
print('今天是%s%s'%(today,'日,加载任务已完工'))

The method of taking specific column data and adding variables in the text can also be multi-variable

Guess you like

Origin blog.csdn.net/Darin2017/article/details/130989965