Sopan_deole
Sopan_deole

Reputation: 39

How can I change x labels to years?

I am working on a data https://www.kaggle.com/rodolfofigueroa/spotify-12m-songs

I wanted to analyze How was the mood of the songs released initially compared with those released in 2020? So I went for plotting year on the x-axis and valence on the y-axis. NOTE- Valence is the Measurement of how positive a track sounds, from 1 (extremely positive) to 0 (extremely negative).

I created this data frame to check the first 20 values and when I am plotting it on the x-axis I am getting row numbers. sorted_df_year['valence'][:20].plot(kind='bar',figsize=(20,5))

My question is how can I change the x-axis label to years (column present in the dataset)?

Upvotes: 1

Views: 65

Answers (1)

r-beginners
r-beginners

Reputation: 35205

Since the expected output is not explicitly stated, I used a bar graph of averages grouped with the x-axis as year. Does it conform to your intended output?

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('./data/tracks_features.csv', sep=',')
df.groupby('year')['valence'].mean().plot(kind='bar', figsize=(20,5))

enter image description here

Upvotes: 0

Related Questions