def shout(word): # Define shout with the parameter, word
"""Return a string with three exclamation marks"""
shout_word = word + '!!!' # Concatenate the strings
return(shout_word) # Replace print with return
hello = shout("congratulations") # Pass 'congratulations' to shout
print(hello)
def shout_all(word1, word2): # Define shout_all with parameters word1 and word2
"""Return a tuple of strings"""
shout1 = word1 + '!!!' # Concatenate word1 with '!!!'
shout2 = word2 + '!!!' # Concatenate word2 with '!!!'
shout_words = (shout1, shout2) # Construct a tuple with shout1 and shout2
return shout_words # Return shout_words
hello1, hello2 = shout_all('congratulations', 'you') # Pass 'congratulations' and 'you' to shout_all()
print(hello1)
print(hello2)
import pandas as pd # Import pandas
tweets_df = pd.read_csv('tweets.csv') # Import Twitter data as DataFrame
def count_entries(df, col_name): # Define count_entries()
"""Return a dictionary with counts of occurrences as value for each key."""
langs_count = {} # Initialize an empty dictionary
col = df[col_name] # Extract column from DataFrame
for entry in col: # Iterate over lang column in DataFrame
if entry in langs_count.keys():
langs_count[entry] += 1 # If the language is in langs_count, add 1
else:
langs_count[entry] = 1 # Else add the language to langs_count, set the value to 1
return langs_count
result = count_entries(tweets_df, 'lang') # Call count_entries() by passing to it tweets_df and the column, 'lang'
print(result)