Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExercícoS011 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions exercicios/para-casa/Claire_ETL_Pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pandas as pd

df = pd.read_csv("C:/git-on33/on33-python-s09-pandas-numpy-I/material/mais_ouvidas_2024.csv")

#print(df.head())
# print(df.columns)
# df_valores_nulos = df.isnull())
# print(df_valores_nulos.sum())
# print(df.duplicated().sum())
#print(df.dtypes)
possible_num_cols = [col for col in df.columns if df[col].dtype == 'object'] # Identificar colunas que podem conter números e que são do tipo 'object'
num_cols = [col for col in possible_num_cols if 'Streams' in col or 'Views' in col or 'Count' in col or 'Likes' in col or 'Spins' in col or 'Reach' in col or 'Rank' in col or 'Stations' in col] # filtrar ainda mais as colunas que têm nomes que indicam que provavelmente contêm números
#print(num_cols)
for col in num_cols:
df[col] = df[col].replace(',', '', regex=True) # Remover caracteres indesejados (exemplo: vírgulas, espaços)
df[col] = df[col].astype(float)
for col in num_cols:
df[col] = df[col].fillna(0).astype(int) # tratar valores em branco
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lembrando que so substituímos valores null por 0 quando queremos dizer que o valor dele é 0. É um ponto de atenção.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agradeço o feedback ;)

#print(df.dtypes)
#df["Release Date"] = pd.to_datetime(df["Release Date"], format="mixed" )
#df["Spotify Popularity"] = df["Spotify Popularity"].fillna(0).astype(int)
#columns_media = ['Spotify Popularity', 'YouTube Views', 'TikTok Likes', 'Shazam Counts']
#df['Streaming Popularity'] = df[columns_media].mean(axis=1) #calcular média

#print(df['Streaming Popularity'].head())
columns_soma = ['Spotify Popularity', 'YouTube Views', 'TikTok Views', 'Pandora Streams', 'Soundcloud Streams']
df['Total Streams'] = df[columns_soma].sum(axis=1)
df['Total Streams'] = df['Total Streams'].fillna(0).astype(int)
#print(df['Total Streams'].head())
#print(df.dtypes)

# Filtre apenas as faixas onde a popularidade do Spotify ('Spotify Popularity') é maior que 80 e que tenham mais de 1 milhão de streams totais ('Total Streams').
filtered_df = df[(df["Spotify Popularity"] > 80 ) & (df["Total Streams"] > 1_000_000)]
print(filtered_df.head())

filtered_df.to_json("./faixas_filtradas.json", index=False)

1 change: 1 addition & 0 deletions exercicios/para-casa/faixas_filtradas.json

Large diffs are not rendered by default.