【发布时间】:2020-01-03 00:37:21
【问题描述】:
我在 Pandas 中有一些 Python 数据框,我想遍历它们以找出哪个数据框符合我的行条件并将其保存在新的数据框中。
d = {'Count' : ['10', '11', '12', '13','13.4','12.5']}
df_1= pd.DataFrame(data=d)
df_1
d = {'Count' : ['10', '-11', '-12', '13','16','2']}
df_2= pd.DataFrame(data=d)
df_2
这是我要使用的逻辑,但它不包含正确的语法,
for df in (df_1,df_2)
if df['Count'][0] >0 and df['Count'][1] >0 and df['Count'][2]>0 and df['Count'][3]>0
and (df['Count'][4] is between df['Count'][3]+0.5 and df['Count'][3]-0.5) is True:
df.save
正确的输出是 df_1... 因为它符合我的条件。如何创建一个新的DataFrame 或LIST 来保存结果?
【问题讨论】:
-
到底是什么问题?你的伪代码看起来不错,为什么不用 Python 写呢?
-
不知道为什么人们投票反对你。您提供了一个带有示例数据的明确问题,并提到您当前的代码引发了语法错误。我会尽快提供答案
标签: python python-3.x pandas loops dataframe