Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
value_count() for only the categorical variables
Post Body

I want to show the value counts for each unique value of each categorical variable in a data frame, but what I've written isn't working. I'm trying to avoid writing separate lines for each individual column if I can help it. Any help would be very much appreciated!

Here's my data frame:

| Column               | Dtype
| -------------------- | ----------
| checking_balance     | category
| months_loan_duration | int64
| credit_history       | category
| purpose              | category
| amount               | int64
| savings_balance      | category
| employment_duration  | category
| percent_of_income    | int64
| years_at_residence   | int64
| age                  | int64
| other_credit         | category
| housing              | category
| existing_loans_count | int64
| job                  | category
| dependents           | int64
| phone                | category
| default              | category

Here's the code I'm trying to run:

for col in creditData.columns:
    if creditData[col].dtype == 'category':
        print(creditData[col].value_counts())

And here's the output that I'm getting back:

unknown       394
< 0 DM        274
1 - 200 DM    269
> 200 DM       63
Name: checking_balance, dtype: int64

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-6a53236835fc> in <module>
      1 for col in creditData.columns: # Loop through all columns in the dataframe
----> 2         if creditData[col].dtype == 'category':
      3                 print(creditData[col].value_counts())

TypeError: data type 'category' not understood

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
31,112
Link Karma
9,875
Comment Karma
20,649
Profile updated: 5 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago