Filling No Instances using Value Counts with 0 – Pandas

Question:

I created a dataframe from valuecounts()[False] looking for all instance where false occured.
However i have since ran into the issue of if no [False] i get the output of "True 110 Name: B_CHECK, dtype: int64".

How can i fix this?

Code:

masterdf

A_CHECK_false_count = (masterdf['A']).value_counts()[False]
B_CHECK_false_count = (masterdf['B']).value_counts()[False] #NO INSTANCES OF FALSE IN COLUMN B
C_CHECK_false_count = (masterdf['C']).value_counts()[False]

d = {'A_CHECK_Total': [A_CHECK_false_count], 
     'B_CHECK_Total': [B_CHECK_false_count], 
     'C_CHECK_Total': [C_CHECK_false_count]}

FalseCountCheck = pd.DataFrame(data=d)

A_Check_Total B_Check_Total C_Check_Total
67 True 110 Name: B_CHECK, dtype: int64 13
Asked By: Cyprus_Knolls

||

Answers:

Given df:

       A     B      C
0   True  True  False
1   True  True  False
2  False  True  False

Doing:

out = df[['A', 'B', 'C']].eq(False).sum().to_frame().T.add_suffix('_Check_Total')
print(out)

Output:

   A_Check_Total  B_Check_Total  C_Check_Total
0              1              0              3
Answered By: BeRT2me
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.