# How to get the number per row of columns that are not 0

• 1 minI had to find a way to get the count of columns per row that weren't 0.

This is how I've done it using the **DataFrame.astype(). **

As you can't use the **DataFrame.count() **method to do this since it takes 0 as a value you have to use the **DataFrame.astype()** method then sum each row's values to have the final count.

As you can see we first transform (cast) our DataFrame into boolean type.

Then we sum up using the **DataFrame.sum()** method by specifying the axis=1 so that we have a sum per row.

Here you are! Now you can get the count of columns that are not 0.

# More on DataFrames

If you want to know more about DataFrame and Pandas. Check out the other articles I wrote on the topic, just here :