返回

python-pandas列必须具有匹配的元素计数

发布时间:2022-07-08 23:41:52 278
# node.js

我有非常大的数据帧。

 data["product_title"]
    0       Fashion Square New Retro Jelly Color Sunglasse...
    1         Fashion Lensless Metal Frame Diamond Sunglasses
    2       Frameless Sunglasses Metal Rice Nails New Larg...
    3       Square Small Frame Marine Sunglasses New Metal...
    4       Fluorescent Green Sunglasses Square Sunglasses...
   

data["price"]
    0       [1.20,  1.20,  1.20,  1.20,  1.20,  1.20,  1.2...
    1                                                  [6.25]
    2       [3.42,  3.42,  3.42,  3.42,  3.42,  3.42,  3.4...
    3       [2.85,  2.85,  2.85,  2.85,  2.85,  2.85,  2.8...
    4       [1.42,  1.42,  1.42,  1.42,  1.42,  1.42,  1.4...

我在列表中有多个产品名称和价格。请看下面的示例,以便您能够理解:

    product title               price
 ["title1","title2",...]      ['5','7',....]     

我尝试了以下代码:

data['product_title'] = data['product_title'].str.strip('[]').str.replace("'", '').str.split(',')
data['price'] = data['price'].str.strip('[]').str.replace("'", '').str.split(',')
data = data.explode(['product_title','price'],ignore_index=True)

收到此错误:

ValueError: columns must have matching element counts

请看截图,因为我认为将完整的错误日志粘贴到这里是不好的。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像