如何将.csv文件中的datetime字符串列拆分为单独的日期和时间列? - python

我在CSV文件中有一个名为date-time的列,其值如下:

"Oct. 25, 2019 12:35:30"

我需要将日期时间列分为两个分别称为datetime的不同列。

不知道如何进行。任何线索都会对我有很大帮助。

参考方案

您可以使用pandas包高效地读取,处理和分析csv文件。

给定一个csv文件,如下所示:

date-time
"Oct. 25, 2019   12:35:30"
"Oct. 26, 2019   13:00:00"

尝试以下操作以实现所需的输出:

#after pip install pandas, import the module
import pandas as pd 

#Read your input csv file
df = pd.read_csv('your_file.csv')

#Convert all the string values of date-time column to datetime objects
df['date-time-obj'] = pd.to_datetime(df['date-time'])

#Create two new columns with date-only and time-only values
df['date-only'] = df['date-time-obj'].dt.date
df['time-only'] = df['date-time-obj'].dt.time

#Deleted temporarily created column
del df['date-time-obj']

#Save your final data to a new csv file
df.to_csv('result.csv', index=False)

输出:

                  date-time   date-only time-only
0  Oct. 25, 2019   12:35:30  2019-10-25  12:35:30
1  Oct. 26, 2019   13:00:00  2019-10-26  13:00:00

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

如何将.wav文件转换为Pandas DataFrame以便将其馈送到神经网络? - python

我正在尝试将.wav文件提供给神经网络,以便对其进行训练以检测所讲的内容。所以我大约有1万个.wav文件和音频的转录,但是当我尝试将CS​​V文件馈送到神经网络时,出现此错误:ValueError: setting an array element with a sequence.我正在使用Soundfile获取没有标题的.wav数据,并将其放入列表中。我也…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…