简体   繁体   English

如何在不导入 pandas 的情况下从 python 中的 csv 文件打印日期

[英]How to print dates from csv file in python without importing pandas

i have data in csv file data as follow 2021-03-26 2021-03-27 2021-04-03我在 csv 文件数据中有数据如下 2021-03-26 2021-03-27 2021-04-03

I want the output as {2021-03-26,2021-03-27,2021-04-03}我希望 output 为 {2021-03-26,2021-03-27,2021-04-03}

you can read the file and its data and split it with space.您可以读取文件及其数据并用空格分割它。

if your csv contains data on multiple lines then you can add for loop for each line and split each line you will get the list of dates.如果您的 csv 包含多行数据,那么您可以为每一行添加 for 循环并拆分每一行,您将获得日期列表。

check below code:检查以下代码:

with open("csv file path", 'r') as fp:
    data = fp.read()
    
data = data.strip()
dates = data.split(' ')
print(dates)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Python 中使用 Pandas 打印 csv 文件中的所有行/数据? - How to print all rows/data from csv file with Pandas in Python? 如何在不为 Python 导入 CSV 的情况下将 CSV 文件中的数据写入字典 - How to write data from a CSV file into a dictionary without importing CSV for Python 如何在没有熊猫的情况下在python中的另一个csv文件中写入一个csv文件 - how to write a csv file in another csv file in python without pandas 使用pandas / python从导入的CSV中选择日期 - Picking dates from an imported CSV with pandas/python python导入没有appostrof标志的csv文件 - python importing csv file without appostrof signs 已解决 - Python Pandas 不导入 .csv。 错误:pandas.errors.EmptyDataError:没有要从文件中解析的列 - SOLVED - Python Pandas not importing .csv. Error: pandas.errors.EmptyDataError: No columns to parse from file Python Pandas:如何从另一个csv文件更新一个csv文件 - Python Pandas: how to update a csv file from another csv file 从 csv 文件导入 python 时如何替换数字 - How to replace numbers when importing from csv file into python 如何在没有熊猫的情况下使用python从CSV文件中获取10个最大值 - How to get the 10 highest values from a CSV file using Python without Pandas 如何使用 vanilla python(不使用 numpy 或熊猫)从 csv 文件中查找列的总和? - How to find the sum of a column from a csv file using vanilla python (without using numpy or pandas)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM