PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Help Required - EDA Python Code Error
Help Required - EDA Python Code Error
Débuté par Mobiwann, 28 juil. 2023 12:17 - Aucune réponse
Posté le 28 juillet 2023 - 12:17
Hello,

I'm working in Python on an exploratory data analysis (EDA) project and I'm having trouble visualising categorical data. I'd want to make a bar plot similar to this example (here:https://www.scaler.com/topics/data-science/how-to-become-a-data-scientist/) to demonstrate the distribution of different automobile manufacturers in my dataset. This is the code I used:
import pandas as pd
import matplotlib.pyplot as plt

# Loading the dataset
data = pd.read_csv('car_data.csv')

# Extracting car brands and their counts
car_brands = data['brand']
brand_counts = car_brands.value_counts()

# Creating the bar plot
plt.bar(car_brands, brand_counts)
plt.xlabel('Car Brands')
plt.ylabel('Count')
plt.title('Distribution of Car Brands')
plt.show()

When I execute the code, however, I receive the following error:
TypeError: '<' not supported between instances of 'str' and 'int'

I'm not sure why I'm seeing this problem or how to resolve it. Could someone kindly explain what's causing this problem and walk me through the proper technique to generate the bar plot for the automobile brands?

Thank you so much for your aid!