generated from reprograma/onX-sx-temaX
-
Notifications
You must be signed in to change notification settings - Fork 32
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
ClaireBP
wants to merge
1
commit into
reprograma:main
Choose a base branch
from
ClaireBP:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ExercícoS011 #5
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
#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) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agradeço o feedback ;)