Skip to content

Working With Lists In DataFrames #36

@IAmAndreasSK

Description

@IAmAndreasSK

Hi,

My group and I use the hashtags #MakeAmericaGreatAgain and #ImWithHer as a basis for our project. However, we would also like to see the other hashtags which the tweets have been using. To that end, we wrote a code that would insert a list of all hashtags used under a "All Hashtags" column for all tweets.

hu=[]
for i in range(len(data["results"])):
    ho=[]
    for d in data['results'][i]['entities']['hashtags']:
        ho.append(str(d["text"]))
    hu.append(ho)
        
df["Hashtag"].copy()[0]=hu[0]

We were wondering the following:

  1. How can we easily count the number of times the different hashtags have been used? We tried df["Hashtag"].value_counts() but that counts the number of times specific lists occur rather than the elements in them. I guess we could do a loop but I'd hope for a more elegant solution.

  2. Is there a way to write the general code in a more 'smooth' way? And should we even use lists in the way we have done?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions