Pandas PatsyError:数据参数和列(statsmodels)之间的行数不匹配

Pandas PatsyError:数据参数和列(statsmodels)之间的行数不匹配,pandas,statsmodels,patsy,Pandas,Statsmodels,Patsy,我正在使用Patsy软件包使用R风格公式与statsmodels合作,收到一个我无法理解的错误,任何提示或技巧都将不胜感激 PatsyError:数据参数和之间的行数不匹配 C(“行业银行和资本市场”)(8137对1) DataFrame确实有8137行,并且没有丢失的数据 完整代码如下 mixed = smf.mixedlm("""count_SoldServiceName ~ date_int + AzureActiveEngagementCount + AzureEngagementPar

我正在使用Patsy软件包使用R风格公式与statsmodels合作,收到一个我无法理解的错误,任何提示或技巧都将不胜感激

PatsyError:数据参数和之间的行数不匹配 C(“行业银行和资本市场”)(8137对1)

DataFrame确实有8137行,并且没有丢失的数据

完整代码如下

mixed = smf.mixedlm("""count_SoldServiceName ~ date_int + AzureActiveEngagementCount + AzureEngagementPartnerCount 
                     + DCount_learning_path_name + Industry_Automotive + C('Industry_Banking&CapitalMarkets') + C('Industry_Chemicals&Agrochemicals') + Industry_CivilianGovernment
                     + Industry_ConsumerGoods + C('Industry_Defense&Intelligence') + Industry_DiscreteManufacturing + Industry_Energy + Industry_Gaming 
                     + Industry_HealthPayor + Industry_HealthProvider + Industry_HigherEducation + Industry_Insurance + C('Industry_Media&Entertainment') + Industry_Nonprofit 
                     + Industry_PartnerProfessionalServices + Industry_Pharmaceuticals + C('Industry_Primary&SecondaryEdu/K-12') + Industry_ProfessionalServices 
                     + C('Industry_PublicSafety&Justice') + Industry_Retailers + Industry_SmartSpaces + Industry_Telecommunications +  C('Industry_Travel,Transport&Hospitality') 
                     + Industry_other + InvestmentArea_AA + InvestmentArea_ACO + InvestmentArea_CSE + InvestmentArea_CSM + InvestmentArea_ECIF + InvestmentArea_FT 
                     + InvestmentArea_GBB + InvestmentArea_PAL + active_flag_int + annual_sales_in_us_dollars + commitment_int 
                     + completed_lp_learners + edx_number_completed_courses + employees_total + esi_offer_int
                     +  health_int + s500_int + segmentname_int + fundamentals_flag + role_based_flag"""                    
                     ,workloads_agg
                     ,groups=workloads_agg['tpid_sub']
                     ,exog_re=workloads_agg['date_int']
                     ,missing='drop'
                   ,use_sqrt=True)
mixed_fit = mixed_complete2.fit(method=['bfgs', 'lbfgs', 'cg','powell'])

以防万一有人碰到这个。解决方案是重命名所有列并删除所有特殊字符的实例,如“、”、“/”、“&”等。

如果我可以添加,在删除所有特殊字符后,还要确保没有额外转义任何列名,例如“column1~columns2+column3”而不是“column1~columns2+column3”