如何将一些Excel文件作为数据帧导入,将日期更改为正确的格式,然后撤回每个文件中的最新日期
我已经开始尝试学习python,以使我的工作中的各种任务更容易。我甚至能够将Excel文件读取到Pandas中,但是我希望能够在大约6个左右的文件中读取我必须定期刷新的文件,请扫描日期列,然后很好地告诉您我是每个文件的最新日期。这是我到目前为止的代码,但我在日期左右会遇到各种错误。文件中我的日期格式是'17/07/2021 13:53',尽管我可以看到有一些类似于'01/06/2022 10:48:02'。我真的只想提取日期并找出这些文件中存在的最新日期,以便我知道它们的最新时间。
pip.main(["install", "openpyxl","Jinja2"])
import re
import pandas as pd
from datetime import datetime
def date_convert(date_to_convert):
return datetime.strptime(date_to_convert,'%d/%m/%Y %H:%M')
#return datetime.strptime(date_to_convert,'%Y/%m/%d %H:%M:%S')
#neither one works????
df_File1 = pd.read_excel (r'File1Location.xlsx')
df_File2 = pd.read_excel (r'File2Location.xlsx')
df_File1['Date String'] = df_File1['Date Created'].astype("string")
df_File1['Date'] = df_File1d['Date String'].apply(date_convert)
print ("File 1","\n",df_File1['Date Created'].max())
我想阅读大约5个左右的这些文件,并具有一个不错的整理输出,就像
-file 1:最新日期:27/04/2022
-file 2:最新日期:24/04/2022
等等等。
I have started trying to learn python to make various tasks within my job easier. I got as far as being able to read an excel file into pandas, but I want to be able to read in about 6 or so files that I have to refresh at regular intervals, have it scan the date column and then nicely and tidily tell me the latest date from each file. This is the code I have so far but I keep getting various errors around date. My date format in the file is '17/07/2021 13:53', although I can see that there are a few that are like '01/06/2022 10:48:02'. I really only want to extract the date and find out the latest date present in these files so I can know how up to date they are.
pip.main(["install", "openpyxl","Jinja2"])
import re
import pandas as pd
from datetime import datetime
def date_convert(date_to_convert):
return datetime.strptime(date_to_convert,'%d/%m/%Y %H:%M')
#return datetime.strptime(date_to_convert,'%Y/%m/%d %H:%M:%S')
#neither one works????
df_File1 = pd.read_excel (r'File1Location.xlsx')
df_File2 = pd.read_excel (r'File2Location.xlsx')
df_File1['Date String'] = df_File1['Date Created'].astype("string")
df_File1['Date'] = df_File1d['Date String'].apply(date_convert)
print ("File 1","\n",df_File1['Date Created'].max())
I would like to read in about 5 or so of these files and have a nice tidy output that is like
-File 1 : Latest Date: 27/04/2022
-File 2 : Latest Date : 24/04/2022
etc and so on and so forth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)