I've data frame as below. I calculate percentile based on inputs provided.
I'd like to get count for each column that matches certain condition. For example, get count in a1 >value1, similarly a2 > value2 and other column.
import pandas as pd
df = pd.DataFrame([[10,11,20],[580,11,20],
[500,11,20],
[110,111,420],[11,11,20],[80,91,90],
[80,91,'NA'],
[10,11,13],[0,14,1111],
[20,104,111],[220,314,1000],[200,30,2000],
[61,31,10],[516,71,20],[10,30,330]],
columns=['a1','a2','a3'])
calculate and describe column based on input percentile, for columns interested. drop NAs
print( (df[["a1","a2","a3"]].dropna()).describe(percentiles =[0.90,0.91,
0.92,0.93,0.94,0.95,0.96,0.97,0.98,0.99] ))
I face certain issues:
Column
a3is removed. How do I save it from being thrown away, but simply throw away that row, or ignore NA?I can get value for each column as:
print(len(df[(df['a1']>200) ]))
print(len(df[(df['a2']>100) ]))
However, this gets tricky and unreadable when data frame has ~10 columns. How do I get counts in a data frame manner for columns for a condition (a1 > 100, a2>90, a3>56 )?
Thank you.