【问题标题】:Getting error "TypeError: unsupported operand type(s) for -: 'list' and 'list'"收到错误“TypeError:不支持的操作数类型 -:'list' 和 'list'”
【发布时间】:2019-08-31 04:56:21
【问题描述】:

TypeError: 不支持的操作数类型 -: 'list' 和 'list'

date_list = [x.strftime('%m/%d/%Y %H:%M') for x in [tframe['Start_Date'].tolist() + timedelta(minutes=30*x) for x in \
                                                    range(0, abs(tframe['End_Date'].tolist() -tframe['Start_Date'].tolist()).days*48)]]

【问题讨论】:

  • 请尝试再写一次,这次不要试图将所有内容都塞进一行。
  • 它可能甚至不需要在这样的列表中,可以在 Pandas 中处理,但很难遵循
  • 您希望tframe['End_Date'].tolist() -tframe['Start_Date'].tolist() 做什么?你不能减去列表。如果要减去它们,为什么要将它们转换为列表?

标签: python pandas dataframe


【解决方案1】:

问题就在这里:

tframe['End_Date'].tolist() - tframe['Start_Date'].tolist()

在 python 中,你不能从另一个列表中减去一个列表。

您似乎正在尝试计算 End_Date 和 Start_Date 之间的时间差。

date_difference的处理方法参考以下链接:

Difference between two dates in Python

【讨论】:

    猜你喜欢
    • 2014-12-28
    • 2012-12-12
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多