python 参数类型int不可迭代

gywdnpxw  于 2023-02-21  发布在  Python
关注(0)|答案(1)|浏览(156)

Post=列表(df ['Posts'])Post 1=列表(),用于Post中的num:如果num中有“k”:新数值=1000* 浮点数(数值替换('k',''))Post 1.追加(新数值)else:Post1.append(浮点数)df ['帖子']= Post 1
类型错误追溯(最近调用最后)输入[37],在〈细胞系:3〉()2 Post 1 =列表()3表示Post中的num:----〉4,如果数值中有'k':5新数值=1000* 浮点数(数值替换('k',''))6后置1.附加(新数值)
TypeError:“int”类型的参数不可迭代
使用范围函数,但仅在colab和jupiter中尝试时出现错误

e0bqpujr

e0bqpujr1#

Pandas允许将条件语句直接应用于 Dataframe 列。强烈建议尝试:

  • Pandas申请和
  • Python语言
df = df.apply(lambda x: 
     1000*float(x['Posts'].replace('k','') 
    if 'k' in x['Posts'] 
    else float(x['Posts']) 
, axis=1 )

免责声明:sudo代码仅在总线上写入,未运行

相关问题