import pandas as pd
df = pd.read_csv('spotify_dataset.csv')
Run to view results
print(df.head())
print(df.dtypes)
Run to view results
print(df.dtypes)
Run to view results
# df['Energy'] = pd.to_numeric(df['Energy'])
Run to view results
import numpy as np
df2 = df.map(lambda x: np.nan if type(x) == str else x)
Run to view results
first_col = "Popularity"
last_col = "Valence"
Run to view results
df2.loc[:, first_col:last_col] = df2.loc[:, first_col:last_col].apply(pd.to_numeric)
Run to view results
from pandas.api.types import is_numeric_dtype, is_string_dtype
Run to view results
num_list = [col for col in df2.columns if is_numeric_dtype(df2[col])]
print(num_list)
Run to view results
print(len(num_list))
type(num_list[3])
Run to view results
df3 = df2.dropna(axis=0)
print(df3.shape)
Run to view results
Run to view results
!pip install altair==5.4.0
Run to view results
import altair as alt
alt.__version__
Run to view results
def make_chart(c):
return alt.Chart(df3).mark_circle().encode(
x='Energy',
y=c,
color='Danceability'
).properties(
width=600,
height=400
)
Run to view results
chart_list = [make_chart(c) for c in num_list]
Run to view results
total_chart = alt.vconcat(*chart_list)
Run to view results
display(total_chart)
Run to view results
with open("total_chart_file.json", "w") as f:
f.write(total_chart.to_json())
Run to view results