3 列通过,通过的数据有 50 列

问题描述

我正在尝试获取 50 件商品的平均价格,当我执行此代码时,我收到一条错误消息,提示通过了 3 列,传递的数据有 50 列。我只需要购买日期、标题和价格这三列。这是代码

function node(){
    // PrevIoUs solved issue
    $("#btnSearchNode").on('click',function () {
        for (var i = 0;i<test_array_node.length;i++){
            if (test_array_node[i].label.indexOf($("#inputSearchNode").val()) >=0 && $("#inputSearchNode").val() != ''){
                test_array_node[i].font = {
                    color:'#FFFFFF',background: '#4A77E0',size: 20
                };
            }else{
                delete test_array_node[i].font;
            }
        }
        new vis.Network(container,data,options);
    });
    
    // Current issue - how to clear above function to be able below function can be click
    network.on('selectNode',function (properties){
        console.log('Node is selected');
    },network.on('selectEdge',function (properties){
        console.log('Edge is selected');
    }
}

解决方法

您要附加整行,而不是单行。一旦你解决了这个问题,它可能会起作用。请注意,.from_records 是可选的,并且指定 columns= 是可选的,因此如果下面的代码不能解决问题,请省略 columns= 并查看您得到了什么。

import pandas as pd
items = results.findAll("li")
rows = []
page_source = wd.page_source
soup = BeautifulSoup(page_source)
for item in items: 
    titleElement = item.find("h3",{"class": "s-item__title s-item__title--has-tags"})
    priceElement = item.find("span",{"class": "s-item__price"})
    dateElement = item.find("span",{"class": "POSITIVE"})
    if titleElement and priceElement and dateElement:
        row = [dateElement.text,titleElement.text,priceElement.text]
        # rows.append(rows)   # this appends all of rows to itself
        rows.append(row)      # append only the 1 additional row
df = pd.DataFrame(rows,columns=["Purchase Date","Title","Price"])

# or if that is still failing:
# df = pd.DataFrame(rows)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...