I need to find number of numerical and categorical columns
Check how many categorical and numerical columns are there
Categorical - object type
Numerical - int,float
Boolean - bool
df = pd.read_csv("titanic.csv")
as i can only get name of the columns with df._get_numeric_data().columns
i need sum of the columns
You can use columns = df.applymap(np.isreal).all(), Output will be,
PassengerId True
Pclass True
Name False
Sex False
Age True
SibSp True
Parch True
Ticket False
Fare True
Cabin False
Embarked False
dtype: bool
All columns with numarical values will return true, othervice return false.
Also, you can get the true and false count using
print((columns).value_counts())
Output :
True 6
False 5
dtype: int64
Which means is df has 6 numerical and 5 categorical columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With