【问题标题】:TypeError: 'DataFrame' object cannot be interpreted as an integer in python 3.7 [duplicate]TypeError:'DataFrame'对象在python 3.7中不能解释为整数[重复]
【发布时间】:2020-07-21 14:19:12
【问题描述】:

我有一个简单的问题,我正在函数内的 dataFrame 列表中创建新列。我收到了这个错误

data['datenum'] = np.zeros((data))

TypeError: 'DataFrame' object cannot be interpreted as an integer

【问题讨论】:

标签: python python-3.x pandas python-2.7


【解决方案1】:

您对 np.zeros 的参数必须是整数。现在你有数据,你说它是一个DataFrame。也许您正在寻找:

data['datenum'] = np.zeros(data.shape[0])

如果您有多个数据框,您可以执行以下操作:

for data in dataframes: 
    data['datenum'] = np.zeros(data.shape[0])

【讨论】:

  • 感谢@ananyajoshi 我实际上有数据帧列表,而不仅仅是单个数据帧
  • 嗨@lffi 不确定您的意思,如果您需要更多帮助,请告诉我更多详细信息!
  • @anayajoshi 我实际上有数据帧列表,例如 df = [df1,df2,df3....] 我在函数中使用它,所以我需要为列表中的每个数据帧创建零列
  • 以上内容现在应该可以使用了,只需将数据框替换为 df。如果是,请接受答案。
猜你喜欢
  • 2016-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-19
  • 1970-01-01
  • 2017-08-01
  • 2021-07-30
  • 1970-01-01
相关资源
最近更新 更多