text_plain_output_1.png
from nltk.corpus import stopwords

from textblob import Word

import nltk

import pandas as pd

import pandas as pd

import tweepy

consumer_key = 'w3M2j4hfO3ByQlROB3W05ooH0'
consumer_secret = 'JmkPXnxlTKV3u5Fnd3xUMor3QF7MIFVJmonXxTN8okLebupXhk'
access_token = '1358404783477043201-A3U7lU8ZvTATIBchtrG5x94nauprT8'
access_token_secret = 'e4F74LVCQ7BWHZ0HPPTF4Tz1laeFJ0a341LPcLQ3jpqvX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

tweets = api.search_tweets(q='BTC', lang='en', count=200)

def hashtag_df(tweets):
    import pandas as pd
    id_list = [tweet.id for tweet in tweets]
    dataframe = pd.DataFrame(id_list, columns=['id'])
    dataframe['user'] = [tweet.author.screen_name for tweet in tweets]
    dataframe['text'] = [tweet.text for tweet in tweets]
    dataframe['hashtags'] = [tweet.entities.get('hashtags') for tweet in tweets]
    return dataframe

df = hashtag_df(tweets)
df = df.drop_duplicates('user', keep='first')
df.drop('id', axis=1, inplace=True)
df.index = df['user']
df.drop('user', axis=1, inplace=True)

df['text'] = df['text'].apply(lambda x: ' '.join((x.lower() for x in x.split())))
df['text'] = df['text'].str.replace('[^\\w\\s]', '')
df['text'] = df['text'].str.replace('\\d', '')
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
sw = stopwords.words('english')
df['text'] = df['text'].apply(lambda x: ' '.join((x for x in x.split() if x not in sw)))
from textblob import Word
nltk.download('wordnet')
df['text'] = df['text'].apply(lambda x: ' '.join([Word(word).lemmatize() for word in x.split()]))
df['text'] = df['text'].str.replace('rt', '')