python - 如何在我的 csv 中获取某些信息?
问题描述
这是我的第一行 csv。我在一列中有 11000 个
"
► Contact with patient | 04.09.2019 | |
► receive the job | 04.09.2019 | |
► contact with patient | 04.09.2019 | |
► take all docs and read | 05.09.2019 | |
► is there any docs to send | 19.09.2019 | |
► take the contract | 20.09.2019 | |
► Actualise the contract | 20.09.2019 | |
► take the contact | 20.09.2019 | | "
我正在尝试获取此 csv 的最后一个书面部分(► 联系 | 20.09.2019 | |),它们都是不同的,有些有 10 个部分,有些有 2 个,但我总是需要最后一个日期才能将其放入新列。我应该使用什么方法?
解决方案
你可以试试:
row = """
Contact with patient | 04.09.2019 | |
receive the job | 04.09.2019 | |
contact with patient | 04.09.2019 | |
take all docs and read | 05.09.2019 | |
is there any docs to send | 19.09.2019 | |
take the contract | 20.09.2019 | |
Actualise the contract | 20.09.2019 | |
take the contact | 20.09.2019 | | """
r = row.split('|') # split in a list
r = r[-4:] # keep the 4 last elements
r = '|'.join(r) # join them together
或在一行中相同:
r = '|'.join(row.split('|')[-4:])
print(r) # 获取联系人 | 20.09.2019 | |
推荐阅读
- c# - 从 Xamarin froms 中的 GestureRecognizers 获取 CommandParameter 值
- matplotlib - 在 matplotlib 中将图表添加到另一个图表
- asp.net-mvc - 如何在 MVC 项目的视图上添加日期选择器
- sql - 与 CTE 一起使用时行号损坏
- javascript - 无法在传单上使用图像叠加插件查看光栅图像(多波段卫星图像)
- python - 更改熊猫的轴替换填充
- docker - Rails 与 Docker-compose:如何设置数据库主机
- html - 如何更改 IOS 中圆角的样式问题?
- javascript - 如何在 amCharts 3 中协调“X”?
- google-analytics - Google Bigquery 标准 SQL - 如何:如果命中包含 sku,则选择命中数,否则选择最大值(命中数)?