Exercício pandas#11
Open
LarissaSchmillevitch wants to merge 2 commits into
Open
Conversation
LarissaSchmillevitch
commented
Aug 14, 2024
- Identifiquei as colunas que contêm números, como 'Spotify Streams', 'YouTube Views', etc., e converta essas colunas para o tipo numérico se estiverem em outro formato. (Use replace() e astype())
- Corriji a coluna 'Release Date' para o formato datetime.
- Criei uma nova coluna chamada 'Streaming Popularity', que seja a média da popularidade nas plataformas 'Spotify Popularity', 'YouTube Views', 'TikTok Likes', e 'Shazam Counts'. (lembrem-se que só é possível calcular médias e fazer operações matemáticas com tipos númericos)
- Criei uma coluna 'Total Streams', somando os valores de 'Spotify Streams', 'YouTube Views', 'TikTok Views', 'Pandora Streams', e 'Soundcloud Streams'.
- Filtrei 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').
- Salvei o DataFrame resultante em um novo arquivo JSON chamado 'faixas_filtradas.json'.
- Garanti que o arquivo foi salvo corretamente
| # Identificar colunas que contêm números e converter para o tipo numérico | ||
| for column in df.columns: | ||
| if df[column].dtype == "object": | ||
| df[column] = df[column].str.replace(",", "").astype(float, errors='ignore') |
Collaborator
There was a problem hiding this comment.
o erro está acontecendo porque está tentando converter colunas que de fato são strings
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.