ComeçarComece de graça

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 exercício faz parte do curso

Feature Engineering para NLP em Python

Ver curso

Exercício interativo prático

Experimente este exercício 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 o código