【问题标题】:string comparison - does not produce the desired result字符串比较 - 不会产生所需的结果
【发布时间】:2015-01-09 08:10:30
【问题描述】:

我有一只熊猫dataframe 在哪里

print type(opp.columns[0])
print type('region')

结果:

<type 'str'>
<type 'str'>

print opp.columns[0]

产生region

我已经用 strip 函数验证了字符串中没有额外的空格。 然而:

print (opps.columns[0].strip() == 'region')

False

【问题讨论】:

  • 你能提供一个可重现的例子吗?
  • 您使用的 oppsopportunities 可能是不同的对象。

标签: python string pandas


【解决方案1】:

您可以使用repr 方法来识别您获得的实际字符串值。可能有像"\n" 这样的隐藏字符,否则不可见

repr(opportunities.columns[0])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 2018-04-25
    • 2010-12-03
    相关资源
    最近更新 更多