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

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



I have a df in below format:


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_Category


Server


Priority


Mined_Category


Server



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,)




1 Answer
1



Need GroupBy.transform for return Series with same size as original df filled by aggregate values:


GroupBy.transform


Series


df


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



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?