Home > Back-end >  How to make a bar plot using seaborn library
How to make a bar plot using seaborn library

Time:12-13

I am trying to make a bar plot on my airline satisfaction data project, I am trying to compare Gender vs. satisfaction answers. I tried the code below in python with sea-born library. I tried plotting both but keep getting DataFrame object has no attribute . I expected a bar plot on Gender vs. Satisfaction.

airline_vis = airline_data.loc[airline_data.columns.str.contains('satisfied|unsatisfied'),:]

sns.countplot(airline_vis.date_time.dt.month,
              hue=airline_vis.columns)
plt.xlabel('Gender')
plt.ylabel('satisfaction')
sns.despine()
plt.legend(loc='upper right')
plt.savefig('gender breakdown')
plt.show()

CodePudding user response:

I hope this solve your problem:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Creating a dictionary with airline gender and satisfaction data
data = {
        'Gender': ['Male', 'Female'],
        'Satisfaction': [3.7, 4.8] # Change satisfaction here
        }

# Transforming the dictionary into a dataframe
df = pd.DataFrame(data)

# Plotting the bar graph
sns.barplot(x="Gender", y="Satisfaction", data=df)

# Defining the chart title
plt.title("Airline Satisfaction by Gender")

# Showing the chart
plt.show()
  • Related