【问题标题】:i need to get the value of x when x greater than y当 x 大于 y 时,我需要获取 x 的值
【发布时间】:2019-07-26 20:33:30
【问题描述】:
df = pd.DataFrame(json_response["data"]["candles"], columns=['Date', 'Open', 'High', 'Low', 'Close', 'Volume'])

x=400
y=300
if(x > y):
print(x)

这里x 是csv 中的一列,其中y 是另一列,如果第一列x > y 然后打印x 的值,其中列值关联

【问题讨论】:

  • 我已经更新了问题请帮助@jezrael
  • 在数据样本中缺少的是DataFrame,有compre scalars,什么不能用于pandas DataFrame中的Series或columns比较
  • 好的,我会用数据框更新
  • 好的,所以我无法正常运行您的代码:(
  • ... 因为 json_response 没有定义

标签: python pandas numpy


【解决方案1】:

只需选择符合您条件的行,然后打印您感兴趣的列:

# result is series
print(df(df["x"]>df["y"])["x"])

# result is array of integers
for result in df(df["x"]>df["y"])["x"].values:
    print(result)

【讨论】:

  • 它不工作我只需要像if (x > y): print (value of x where x is greater)
  • 扩展了我的示例,仅打印值,而不是系列对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多