Comece agoraComece grátis

Hashtags e menções em tweets em russo

Vamos revisar o dataframe tweets com tweets em russo. Neste exercício, você vai calcular o número de hashtags e menções em cada tweet, definindo duas funções, count_hashtags() e count_mentions(), respectivamente, e aplicando-as ao atributo content de tweets.

Se você não se lembra, os tweets estão armazenados no atributo content de tweets.

Este exercicio faz parte do curso

Feature Engineering para NLP em Python

Ver curso

exercicio interativo prático

Tente este exercicio completando este código de exemplo.

# Function that returns numner of hashtags in a string
def count_hashtags(string):
	# Split the string into words
    words = string.split()
    
    # Create a list of words that are hashtags
    hashtags = [word for word in words if ____.____(____)]
    
    # Return number of hashtags
    return(len(hashtags))

# Create a feature hashtag_count and display distribution
tweets['hashtag_count'] = tweets['content'].apply(count_hashtags)
tweets['hashtag_count'].hist()
plt.title('Hashtag count distribution')
plt.show()
Editar e Executar Código