【问题标题】:is argument type int is not iterable是参数类型 int 是不可迭代的
【发布时间】:2023-02-20 23:01:52
【问题描述】:

帖子=列表( df ['帖子']) 帖子 1=列表() 对于帖子中的数字: 如果数字中有“k”: new_num=1000*float(num.replace('k','')) Post1.append(new_num) 别的: Post1.append(float(num)) df['帖子']=帖子1


TypeError Traceback(最后一次调用) 在 [37] 中输入 <cell line: 3>() 2 Post1=列表() 3 for num in Post: ----> 4 if 'k' in num: 5 new_num=1000*float(num.replace('k','')) 6 Post1.append(new_num)

类型错误:“int”类型的参数不可迭代

使用范围函数但仅在 colab 和 jupiter 中都尝试过时出现错误

【问题讨论】:

    标签: python data-science


    【解决方案1】:

    Pandas 允许将条件语句直接应用于数据框列。强烈推荐尝试:

    • 熊猫应用和
    • 蟒蛇拉姆达。
    df = df.apply(lambda x: 
         1000*float(x['Posts'].replace('k','') 
        if 'k' in x['Posts'] 
        else float(x['Posts']) 
    , axis=1 )
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多