Any suggestions for elegant ways to make the following counts for each column in my dataframe:
- Count of elements in the column which are numeric (any value)
- Count of elements in the column which are numeric and nonzero
Here's some code to generate a dataframe like mine (but much smaller):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#from matplotlib import style
import seaborn as sns
df = pd.DataFrame(data=np.random.random_integers(low=0,high=10,size=(50,1)),
columns=['all']
)
# set up the grouping
g = df.groupby(pd.cut(df['all'],[-1,2,4,6,8,10]))
for name, data in g.groups.items():
df[name] = df.loc[data]['all']
This produces a dataframe that looks like the following:
