【问题标题】:Error while creating crosstab from a data set从数据集创建交叉表时出错
【发布时间】:2018-09-05 17:51:46
【问题描述】:

我想对两个列名 customerid (cid) 和 state 进行聚类:

cid = np.array(b.customerID)
state = np.array(b.State)
pd.crosstab(ind, [cid, state], rownames=['cid'], colnames=['state'], dropna = False)

当我尝试在 Python 中创建交叉表时,它向我展示了

数组和名称的长度必须相同

请大家帮帮我。

【问题讨论】:

    标签: python pandas numpy dataframe machine-learning


    【解决方案1】:

    我认为不需要转换为 numpy 数组,colnames 需要 2 个值:

    df = pd.crosstab(df.ind, [df.customerID, df.State], 
                     rownames=['ind'], 
                     colnames=['cid','state'], dropna = False)
    

    【讨论】:

      【解决方案2】:

      crt=pd.crosstab(b.State,b.customerID,margins=True)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-05
        • 2014-01-29
        • 1970-01-01
        • 2016-09-20
        • 1970-01-01
        相关资源
        最近更新 更多