【问题标题】:How can I pass a pandas data frame into a request parameter如何将熊猫数据框传递给请求参数
【发布时间】:2019-11-21 14:50:14
【问题描述】:

我正在尝试做这样的事情:

df = pd.read_csv(r'Desktop/test.csv')

url = 'http://localhost:5000/run_model'

response = requests.post(url, data=df)

但我遇到了这个错误:

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

【问题讨论】:

  • 只传递文件本身

标签: python pandas python-requests


【解决方案1】:

根据您的端点,您可以将 DataFrame 转换为 CSV 或 json 格式

df.to_json()

df.to_csv()

【讨论】:

  • 是的...我想这是不可能将其作为熊猫数据框传递的,您需要将其转换为 json 例如
猜你喜欢
  • 2021-07-14
  • 2015-01-13
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多