Bar Chart using Python with pandas and matplotlib (Data Science)

ByteUprise
1 min readFeb 15, 2024

--

Gradient Blur Hot Pink Oval Illustration Orange Blur Circle Illustration 3D Gradients Oversaturated Rainbow Color 3D Gradients Oversaturated Rainbow Color Generate a bar chart or histogram to visually represent the distribution of a categorical or continuous variable, such as the age distribution or gender composition within a population. This graphical representation offers a clear and insightful overview of the data’s patterns and trends.

Dataset : https://www.kaggle.com/datasets/abhishekvermasg1/support-vector-machine-svm

Steps:

Let’s say we want to visualize the distribution of the target variable “Personal Loan” in this SVM dataset.

Here’s how you can do it using Python with pandas and matplotlib:

```python
import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset
data = pd.read_csv(“support-vector-machine-svm/UniversalBank.csv”)

# Plot the distribution of the ‘Personal Loan’ variable (target variable)
plt.figure(figsize=(8, 6))
data[‘Personal Loan’].value_counts().plot(kind=’bar’, color=[‘skyblue’, ‘salmon’])
plt.title(‘Distribution of Personal Loan (Class)’)
plt.xlabel(‘Personal Loan’)
plt.ylabel(‘Count’)
plt.xticks([0, 1], [‘Not Taken’, ‘Taken’], rotation=0)
plt.show()
```

This code will generate a bar chart showing the distribution of the “Personal Loan” variable in the dataset, indicating how many individuals have taken or not taken a personal loan.

Make sure to adjust the column names and visualization parameters according to your specific dataset and requirements. Let me know if you need further assistance!

@ByteUprise

--

--

ByteUprise
ByteUprise

No responses yet