我有一个带有DataTime列的数据框(时区的格式不同)。看来时区是UTC,但我想将列转换为pd.to_datetime,但失败了。那就是问题1。由于失败了,因此我无法在该时间段上执行任何datetime操作,例如按日期分组/确定日期/按小时分组等等。这是我的数据框df_res
DateTime
2017-11-02 19:49:28-07:00
2017-11-27 07:32:22-08:00
2017-12-27 17:01:15-08:00
Run Code Online (Sandbox Code Playgroud)
命令的输出
df_res["DateTime"] = df_res["DateTime"].dt.tz_convert('America/New_York')
Run Code Online (Sandbox Code Playgroud)
AttributeError: Can only use .dt accessor with datetimelike values
当我转换为 datetime
df_res['DateTime'] = pd.to_datetime(df_res['DateTime'])
Run Code Online (Sandbox Code Playgroud)
ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
我觉得我正在转圈。我需要将列转换为日期时间才能执行操作,并且为了做到这一点,我需要将它们全部设置为相同的时区,但除非具有日期时间对象,否则我就不能使用相同的时区,因此,如何最好地实现这一点。我确实提到了以前的帖子,但它们似乎尽可能容易地转换为日期时间:
将datetime列转换为其他时区pandas 将pandas时区感知的DateTimeIndex转换为朴素时间戳,但在特定时区
我的数据框中有两列 - 开始日期和完成日期(它是时间戳)。我想通过找出差异来计算运行时间。当我运行下面的代码时,出现错误:TypeError: cannot subtract DatetimeArray from ndarray。我也无法将完成日期列拆分为日期和时间,以便我可以以另一种方式计算运行时间。
# calculate runtime
pd.to_datetime(df.start_date)
pd.to_datetime(df.finish_date)
diff = pd.to_datetime(df.finish_date) - pd.to_datetime(df.start_date)
Run Code Online (Sandbox Code Playgroud)
数据框如下所示: df
file_name unique_id start_date finish_date
file1 1716b94a8d8d83c8fffe4bdd14d536ae1ee9cba6bf17e6... 2020-09-03T16:18:38.929863799Z 2020-09-03T16:20:17.615093582Z
file2 87ff84ab119b798312230fceb3a8730fe74669a373650a... 2020-09-03T16:26:25.075167073Z 2020-09-04T00:04:39.702686798Z
Run Code Online (Sandbox Code Playgroud)
我怎么能够 -
使用 gitlab-python 包,我想从所有 Dockerfile 中提取行。使用下面的代码,我可以获取项目名称和我想要的存储库的 url,但如何确保存在 Dockerfile 并读取 Dockerfile 的内容。
import gitlab
import json
from pprint import pprint
import requests
import urllib.request
# private token authentication
gl = gitlab.Gitlab('<path_to_gitlab_repo>', private_token=<token_here>)
gl.auth()
# list all projects
projects = gl.projects.list()
for project in projects:
# print(project) # prints all the meta data for the project
print("Project: ", project.name)
print("Gitlab URL: ", project.http_url_to_repo)
# print("Branches: ", project.repo_branches)
pprint(project.repository_tree(all=True))
f = urllib.request.urlopen(project.http_url_to_repo)
myfile = f.read()
print(myfile)
print("\n\n")
Run Code Online (Sandbox Code Playgroud)
我现在得到的输出是:
Gitlab URL: <path_to_gitlab_repo>
[{'id': '0c4a64925f5c129d33557',
'mode': …Run Code Online (Sandbox Code Playgroud)