2020-09-08
阅读量:
1188
python筛选excel中各列内容均相同的数据中的日期格式处理
In [19]:
import pandas as pd df=pd.read_excel(r'D:\CDA\CDA_PGC\datas.xlsx',sheetname='Sheet1') df
Out[19]:
编号 | 日期 | |
---|---|---|
0 | 123 | 2020-09-09 |
1 | 123 | 2020-09-08 |
2 | 345 | 2020-09-09 |
3 | 345 | 2020-09-08 |
4 | 345 | 2020-09-09 |
5 | 123 | 2020-09-09 |
In [20]:
df=df.drop_duplicates()
In [21]:
df['日期']=df['日期'].dt.date.apply(str) #日期格式只取日期,并转换为字符串,否则导出到excel后,会自动添加时分秒。
In [22]:
df
Out[22]:
编号 | 日期 | |
---|---|---|
0 | 123 | 2020-09-09 |
1 | 123 | 2020-09-08 |
2 | 345 | 2020-09-09 |
3 | 345 | 2020-09-08 |
In [23]:
df.to_excel(r'D:\CDA\CDA_PGC\datas2.xlsx',index=None)#删除index列






评论(0)


暂无数据