在 pandas 文档说明书的 if-then 部分,我们可以根据使用loc[].
df = pd.DataFrame({'AAA' : [4,5,6,7],
'BBB' : [10,20,30,40],
'CCC' : [100,50,-30,-50]})
# AAA BBB CCC
# 0 4 10 100
# 1 5 20 50
# 2 6 30 -30
# 3 7 40 -50
df.loc[df.AAA >= 5,'BBB'] = -1
# AAA BBB CCC
# 0 4 10 100
# 1 5 -1 50
# 2 6 -1 -30
# 3 7 -1 -50
Run Code Online (Sandbox Code Playgroud)
但是,如果我想使用 编写涉及前一行或后一行的条件.loc[]怎么办?例如,假设我想分配当前行和下一行df.BBB=5之间的差值大于或等于 50 …
我.timestamp()在代码中两次使用该函数,将日期时间对象转换为纪元时间。第一次调用.timestamp()看起来像这样:
import datetime
origin_epoch = origin.timestamp()
Run Code Online (Sandbox Code Playgroud)
变量的内容origin和origin_epoch有:
同时,如果我尝试在代码的其他地方调用相同的方法
import datetime
print(datetime.datetime(1900, 1, 1, 19, 6, 28).timestamp())
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误:OSError: [Errno 22] Invalid argument这是为什么?
编辑:此错误发生在 Windows 10 上。
我在练习 LeetCode 问题(诚然很简单)时遇到了我的问题。然而,我真正的问题是关于Python的,而不是问题本身的答案。您将在下面看到完整的问题陈述,然后我解释我的方法,将其与实际解决方案进行对比,然后(最后)提出我的问题。
问题:
编写一个函数来删除单链表中的节点(尾部除外),并且只能访问该节点。
给定链表 -- head = [4,5,1,9],如下所示:

示例1:
Input: head = [4,5,1,9], node = 5
Output: [4,1,9]
Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
Run Code Online (Sandbox Code Playgroud)
示例2:
Input: head = [4,5,1,9], node = 1
Output: [4,5,9]
Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function. …Run Code Online (Sandbox Code Playgroud)