python-3.x - 无法将多个日期时间对象提取到数据框中的一个单元格中
问题描述
我有几句话,我将每个句子放在数据框的一行中。我正在研究从这些句子中提取日期。我遇到了“datefinder”这个包。
当我将单个句子发送到“string_with_dates”时,它会正确提取所有日期并返回。
import datefinder
string_with_dates = ''' They have released Proposals for period October 1, 2018 ’ September 30, 2019. Manufacturers are encouraged to submit proposals for stores located basis throughout the fiscal year ending September 30, 2018, pending availability of funds., '''
matches = datefinder.find_dates(string_with_dates)
for match in matches:
match = str(match)
print(match)
output = 2018-10-01 00:00:00
2019-09-30 00:00:00
2018-09-30 00:00:00
但是,当我放置一个数据框的多个句子并使用“for”循环进行循环时,它就会变得一团糟。它不会在数据框的单元格中正确显示多个日期(如果有)。description_df 是我的数据框的名称。在第 9 列中,我有句子,在第 13 列中,我希望存储提取的日期。
import datefinder
for i in range (len(description_df)):
string_with_dates = description_df.iloc[i,9]
matches = datefinder.find_dates(string_with_dates)
for match in matches:
match = str(match)
print(match)
description_df.iloc[i,13] = match
Output of the extracted date column of the dataframe is:
2019-09-30 00:00:00
2019-05-07 00:00:00
""
0310-08-07 00:00:00
2019-08-07 00:00:00
解决方案
推荐阅读
- redirect - linux sh; 从非 root 特权用户的脚本中将 stdout/stderr 重定向到 [root,adm] 拥有的目录
- python - python, power function using one loop
- python - OpenCV(4.1.2)错误!_src.empty()在函数'cvtColor'中
- c# - 如何在.net core中绑定数据模型对象的属性名称
- github-actions - 当有人取消作业时,如何在 GitHub 操作中挂钩和执行清理命令?
- javascript - 找出所有包含大括号的单词
- python - python:如何使用 doc _id 检查 Elasticsearch 中是否存在文档
- r - 获取数据帧的值作为向量
- javascript - 如何在 JS API for MS365 excel labscript 中拆分单元格
- java - AsyncTask 如何将一个进程工作到另一个进程?