简体   繁体   中英

Pandas Bar plot

I have a data frame 'df'. I created a separate data frame 'df_top', displaying the cities with the highest total revenue from the original frame. I want to compare the 2 column values (Cities & Customer Status) from the new data frame (df_top) through a bar plot.

Data frame (new_df):

Customer ID Gender  Age Married Number of Dependents    City    Zip Code    Latitude    Longitude   Number of Referrals ... Payment Method  Monthly Charge  Total Charges   Total Refunds   Total Extra Data Charges    Total Long Distance Charges Total Revenue   Customer Status Churn Category  Churn Reason
31  0048-PIHNL  Female  48  Yes 0   Los Angeles 90058   34.001617   -118.222274 5   ... Bank Withdrawal 20.45   900.90  0.0 0   2429.42 3330.32 0   missing missing
32  0052-DCKON  Male    28  Yes 0   Los Angeles 90063   34.044271   -118.185237 9   ... Bank Withdrawal -2.00   7942.15 0.0 0   2888.82 10830.97    0   missing missing
37  0060-FUALY  Female  60  Yes 0   Los Angeles 90003   33.964131   -118.272783 4   ... Bank Withdrawal 94.75   5597.65 0.0 0   967.01  6564.66 0   missing missing
40  0067-DKWBL  Male    69  No  0   San Diego   92129   32.961064   -117.134917 0   ... Bank Withdrawal 49.25   91.10   0.0 0   87.98   179.08  1   Competitor  Competitor made better offer
43  0074-HDKDG  Male    46  Yes 0   San Jose    95126   37.327069   -121.916819 5   ... Bank Withdrawal 61.60   1611.00 44.9    0   161.25  1727.35 0   missing missing

My code:

# Relationship between top 5 'Cities' and 'Customer Status'

df_top = df[df["City"].isin(["Los Angeles", "San Diego", "Sacramento", "San Jose", "San Francisco"])]

df_top.plot.bar(x = 'City', y = 'Customer Status')

My bar plot:

我的条形图

Why is my bar plot displaying like this and how do I resolve this issue? Thanks.

df.plot(x="city", y=["customer status"], kind="bar")

I believe that in your dataset "customer status" column is of float data type. I simulate your problem in my machine and by above mention piece of code, I get the result.

Library and Platform that I used

  1. Development platform: Google colab

  2. pandas version: 1.3.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM