Seaborn Barplot Method

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = {
    'Fruit': ['Apple', 'Mango', 'Apple', 'Mango', 'Apple', 'Mango'],
    'Sales': [100, 80, 90, 70, 95, 85]
}
df = pd.DataFrame(data)
print(df)
# Bar plot showing average sales for each fruit
sns.barplot(x='Fruit', y='Sales', data=df,ci=None,estimator=np.sum)
plt.title("Average Sales of Fruits")
plt.show()

Program 2

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df_tips = sns.load_dataset('tips')
#print(df_tips.head())
print(df_tips.info())

#sns.barplot(x='day', y='total_bill', data=df_tips, hue='sex',ci=None,estimator=np.median,palette='Accent')
# sns.barplot(x='day', y='tip', data=df_tips, hue='sex',ci=None,estimator=np.mean)
sns.barplot(x='time', y='tip', data=df_tips, hue='sex',ci=None,estimator=np.mean)
plt.title("Average Total Bill per Day")
plt.show()

 

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *