简体   繁体   English

ValueError: 操作数无法与形状一起广播 (7410,) (3,)

[英]ValueError: operands could not be broadcast together with shapes (7410,) (3,)

I have a df in below format:我有以下格式的 df:

    Priority Mined_Category           server date_reported  Count Zscore_Volume
1 - Critical   Memory issue        xxxxxx111    2018-07-11      1      nan
1 - Critical   Memory issue        xxxxxx111    2018-08-11      1      nan
1 - Critical   Memory issue        yyyyyy195    2018-07-06      1      1.71
1 - Critical   Memory issue        yyyyyy195    2018-07-08      1      1.71
    2 - High   Memory issue  abcabcabcba1410    2018-08-21      1     nan

my aim is to replace nan with 100 whenever Priority Mined_Category and Server groupby count is 1 and replace nan with 1000 whenever Priority Mined_Category and Server groupby count is >1我的目标是在Priority Mined_CategoryServer groupby 计数为 1 时将 nan 替换为 100,并在Priority Mined_CategoryServer groupby 计数大于 1 时将 nan 替换为 1000

I tried below code:我试过下面的代码:

> df_aggegrate_Volume.loc[(df_aggegrate_Volume.groupby(["Priority","Mined_Category","server"]).count()>1)&(df_aggegrate_Volume['Zscore_Volume'].isnull()) ,"Zscore_Volume"]= -100

but I get below error:但我得到以下错误:

ValueError: operands could not be broadcast together with shapes (7410,) (3,) ValueError: 操作数无法与形状一起广播 (7410,) (3,)

Need GroupBy.transform for return Series with same size as original df filled by aggregate values:需要GroupBy.transform以返回与由聚合值填充的原始df大小相同的Series

m1 = (df_aggegrate_Volume.groupby(["Priority","Mined_Category","server"])["server"]
                         .transform('count')>1)

m2 = df_aggegrate_Volume['Zscore_Volume'].isnull()

df_aggegrate_Volume.loc[m1 & m2 ,"Zscore_Volume"]= -100

print (df_aggegrate_Volume)
       Priority Mined_Category           server date_reported  Count  \
0  1 - Critical   Memory issue        xxxxxx111    2018-07-11      1   
1  1 - Critical   Memory issue        xxxxxx111    2018-08-11      1   
2  1 - Critical   Memory issue        yyyyyy195    2018-07-06      1   
3  1 - Critical   Memory issue        yyyyyy195    2018-07-08      1   
4      2 - High   Memory issue  abcabcabcba1410    2018-08-21      1   

   Zscore_Volume  
0        -100.00  
1        -100.00  
2           1.71  
3           1.71  
4            NaN  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python - ValueError:操作数无法与形状一起广播 - Python - ValueError: operands could not be broadcast together with shapes ValueError: 操作数无法与形状 (3,) (3000,) 一起广播 - ValueError: operands could not be broadcast together with shapes (3,) (3000,) Pandas:ValueError - 操作数无法与形状一起广播 - Pandas: ValueError - operands could not be broadcast together with shapes Python ValueError:操作数无法与形状一起广播 - Python ValueError: operands could not be broadcast together with shapes ValueError: 操作数无法与形状 (7,) (6,) (7,) 一起广播 - ValueError: operands could not be broadcast together with shapes (7,) (6,) (7,) ValueError:操作数不能与形状(5,)(30,)一起广播 - ValueError: operands could not be broadcast together with shapes (5,) (30,) QuantileRegression ValueError:操作数无法与形状一起广播 - QuantileRegression ValueError: operands could not be broadcast together with shapes ValueError:操作数无法与形状一起广播 (3,5) (3,) - ValueError: operands could not be broadcast together with shapes (3,5) (3,) ValueError:操作数不能与形状一起广播 - ValueError: operands could not be broadcast together with shapes ValueError:操作数不能与形状(3,)(100,)一起广播 - ValueError: operands could not be broadcast together with shapes (3,) (100,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM