(这个问题可以单独阅读,但是续集:来自CSV数据的时间序列(时间戳和事件))
我想通过时间序列表示,使用python的pandas模块(参见下面的链接)可视化CSV数据(来自2个文件),如下所示.
df1的示例数据:
TIMESTAMP eventid
0 2017-03-20 02:38:24 1
1 2017-03-21 05:59:41 1
2 2017-03-23 12:59:58 1
3 2017-03-24 01:00:07 1
4 2017-03-27 03:00:13 1
Run Code Online (Sandbox Code Playgroud)
'eventid'列始终包含值1,我试图显示数据集中每天的事件总和.第二个数据集df0具有相似的结构,但仅包含零:
df0的示例数据:
TIMESTAMP eventid
0 2017-03-21 01:38:24 0
1 2017-03-21 03:59:41 0
2 2017-03-22 11:59:58 0
3 2017-03-24 01:03:07 0
4 2017-03-26 03:50:13 0
Run Code Online (Sandbox Code Playgroud)
x轴标签只显示相同的日期,我的问题是:如何显示不同的日期?(是什么导致在x标签上多次显示相同的日期?)
脚本到目前为止:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
df1 = pd.read_csv('timestamp01.csv', parse_dates=True, index_col='TIMESTAMP')
df0 = pd.read_csv('timestamp00.csv', parse_dates=True, index_col='TIMESTAMP')
f, (ax1, ax2) = plt.subplots(1, …Run Code Online (Sandbox Code Playgroud) 如何在一个命令中比较 2 个文件的 md5 和?
我可以分别计算它们:
my_prompt$ md5sum file_1.sql
20f750ff1aa835965ec93bf36fd8cf22 file_1.sql
my_prompt$ md5sum file_2.sql
733d53913c366ee87b6ce677971be17e file_2.sql
Run Code Online (Sandbox Code Playgroud)
但想知道如何将其合并到单个比较计算中。我尝试过不同的方法但都失败了:
my_prompt$ md5sum file_1.sql == md5sum file_2.sql
my_prompt$ `md5sum file_1.sql` == `md5sum file_2.sql`
my_prompt$ (md5sum file_1.sql) == (md5sum file_2.sql)
my_prompt$ `md5sum file_1.sql` -eq `md5sum file_2.sql`
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?尝试了以下Compare md5 sums in bash script和https://unix.stackexchange.com/questions/78338/a-simpler-way-of-comparing-md5-checksum,但没有运气。
我正在尝试在 f 字符串中使用命名表达式:
print(f"{(a:=5 + 6) = }")
Run Code Online (Sandbox Code Playgroud)
返回:
(a:=5 + 6) = 11
Run Code Online (Sandbox Code Playgroud)
但我希望有这样的事情:
a = 11
Run Code Online (Sandbox Code Playgroud)
通过组合海象运算符和 f 字符串是否可能(这样我就不必a在单独的步骤中首先声明变量)?
python string-interpolation python-3.x f-string walrus-operator
我希望删除之前和之后的行对 column 具有相同值的行num2。我的数据框如下所示:
import pandas as pd
df = pd.DataFrame([
[12, 10],
[11, 10],
[13, 10],
[42, 11],
[4, 11],
[5, 2]
], columns=["num1", "num2"]
)
Run Code Online (Sandbox Code Playgroud)
这是我的目标:
df = pd.DataFrame([
[12, 10],
[13, 10],
[42, 11],
[4, 11],
[5, 2]
], columns=["num1", "num2"]
)
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
df["num1_diff"] = df["num2"].diff().fillna(0).astype(int)
filt = df["num1_diff"].apply(lambda x: x == 0)
print(df[filt])
Run Code Online (Sandbox Code Playgroud)
给予:
num1 num2 num1_diff
0 12 10 0
1 11 10 0
2 13 10 0
4 4 11 0
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用新num1_diff …
我想使用rotate_deg_around()函数围绕其左下角旋转matplotlib矩形面片对象。然而,补丁总是围绕某个不同的点旋转。知道为什么rotate_deg_around()函数没有产生期望的结果吗?
我的代码如下:
f,(ax1) = plt.subplots(1,1,figsize=(6,6))
f.subplots_adjust(hspace=0,wspace=0)
ts = ax1.transData
coords = ts.transform([1,1])
tr = mpl.transforms.Affine2D().rotate_deg_around(coords[0], coords[1], 10)
t = ts + tr
rec0 = patches.Rectangle((1,1),3,2,linewidth=1,edgecolor='r',facecolor='none')
ax1.add_patch(rec0)
#Rotated rectangle patch
rect1 = patches.Rectangle((1,1),3,2,linewidth=1,edgecolor='b',facecolor='none',transform=t)
ax1.add_patch(rect1)
# Rectangles lower left corner
plt.plot([1], [1], marker='o', markersize=3, color="green")
plt.grid(True)
ax1.set_xlim(0,6)
ax1.set_ylim(-1,4)
Run Code Online (Sandbox Code Playgroud)
得到下图:
我遵循 Unable to spin a matplotlib patch object about a certain point usingrotate_around( )
任何帮助深表感谢。
我们想在给定的字符串 s 中找到乘以无限次的 'a' 的数量。我们将得到一个数字 n,它是无限字符串的切片大小。样本输入 aba 10
输出:- 7 此处 aba 乘以 10 产生 'abaabaabaa' 并且 'a's 的数量是 7 这是我的代码
def repeatedString(s, n):
count = 0
inters = s * n
reals = s[0:n+1]
for i in reals:
if (i == 'a'):
count += 1
return count
Run Code Online (Sandbox Code Playgroud)
我得到 2 而不是 7 作为输出(测试用例 'aba' 10)。我哪里做错了?我只是将给定的字符串与 n 相乘,因为它永远不会大于切片大小。
这是问题的链接 https://www.hackerrank.com/challenges/repeated-string/problem
在我的 Azure DevOps 管道中
(https://dev.azure.com/TheNewThinkTank/dark-matter-attractor/_build?definitionId=2&_a=summary)
我有一个测试阶段,我希望在相应的 Azure DevOps 存储库中的所有 Python 文件上安装并运行 pytest
(https://dev.azure.com/TheNewThinkTank/_git/dark-matter-attractor)。
Pytest的安装和运行方式遵循微软官方文档:
- script: |
pip install pytest
pip install pytest-cov
pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
displayName: 'Test with pytest'
Run Code Online (Sandbox Code Playgroud)
可以在以下位置找到:https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python ?view=azure-devops
运行 Pipeline 会导致上述步骤出错:
pytest: command not found
如果您想查看完整的回溯:
我尝试过的其他事情:
在官方 pytest 网站(https://docs.pytest.org/en/stable/getting-started.html)之后,我尝试向安装命令添加一个标志:
pip install -U pytest,但结果相同。
是什么阻止管道发现已安装的 pytest 模块?
我正在使用 AWS CloudFormation(基于 YAML)来部署 IAM 角色。应允许该角色部署其他 CloudFormation 资源,并拥有其作为可信实体部署到的 AWS 账户的根。我尝试使用内置伪参数提供帐户 ID AWS::AccountId:
https: //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html#cfn-pseudo-param-帐户ID。
这是我按照官方文档尝试过的: https: //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-policy.html(仅显示resources我的 CFN 模板的部分):
Resources:
IAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: ["sts:AssumeRole"]
Effect: Allow
Principal:
Service: [cloudformation.amazonaws.com]
AWS: arn:aws:iam::AWS::AccountId:root # <-- ERROR HERE !
Run Code Online (Sandbox Code Playgroud)
MalformedPolicyDocument由于Invalid principalCloudFormation 堆栈中的 (在 AWS 管理控制台中的 下Events),这会导致错误:
Invalid principal in policy: "AWS":"arn:aws:iam::AWS::AccountId:root" (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument
Run Code Online (Sandbox Code Playgroud)
我尝试过改变主体值的语法AWS:
校长的错误在哪里,如何纠正?
python ×6
python-3.x ×3
bash ×2
dataframe ×2
matplotlib ×2
pandas ×2
amazon-iam ×1
azure-devops ×1
f-string ×1
md5 ×1
md5sum ×1
pytest ×1
string ×1
time-series ×1
ubuntu ×1