<jupyter_start><jupyter_text>all steps and instructions of this py file1.read all csv2.def clean(tweet): that will clean @___/ / links. we keep retweets because we think there are still some relations between retweets and btc3.generate 3 columns: polarity, subjectivity, polarity2(+/-/0)<jupyter_code># pip install textblob
import pandas as pd
import re # cleaning text
from textblob import TextBlob #sentiment analysis
elon =  pd.read_csv('merged_data_elonmusk.csv') #read all csv files
CathieDWood =  pd.read_csv('merged_data_CathieDWood.csv')
chamath =  pd.read_csv('merged_data_chamath.csv')
LilMoonLambo =  pd.read_csv('merged_data_LilMoonLambo.csv')
tyler =  pd.read_csv('merged_data_tyler.csv')
UniswapD =  pd.read_csv('merged_data_UniswapD.csv')
VitalikButerin =  pd.read_csv('merged_data_VitalikButerin.csv')
def clean(tweet): # Remove @xxx, #, links #then insert col to df right of tweet
    #we keep retweets because we think there are still some relations between retweets and btc
    tweet = re.sub(r"https?:\/\/\S+", "", tweet)
    tweet = re.sub(r"#", "", tweet)
    tweet = re.sub(r"@[A-Za-z0-9]+", "", tweet)
    return tweet
def insert_clean_col(df): #insert col with cleaned text, just next to tweet col
    df.insert(loc=3, column='cleanedtweet', value=df["tweet"].apply(clean))
insert_clean_col(elon)
insert_clean_col(CathieDWood)
insert_clean_col(chamath)
insert_clean_col(LilMoonLambo)
insert_clean_col(tyler)
insert_clean_col(UniswapD)
insert_clean_col(VitalikButerin)
elon.head(2)

# define a function, that can return two columns, polarity and subjectivity analysis of the cleanedtweet column
def sub_and_polar_col(df):
    return pd.Series([TextBlob(df["cleanedtweet"]).sentiment.polarity, TextBlob(df["cleanedtweet"]).sentiment.subjectivity])

#this one is just for kinda 'visualizing' polarity by changing to positive, negative, 0 instead of numbers
def polar2_col(value):
    if value == 0:
        return "0"
    elif value > 0:
        return "positive"
    else:
        return "negative"

def insert_sub_pol_col(df): #insert polarity, subjectivity, and polarity2(+-0) three columns into df
    df[["polarity","subjectivity"]] = df.apply(sub_and_polar_col, axis=1) #axis1 means column
    df[['polarity2']]=df['polarity'].apply(polar2_col)
#use the function for all df
insert_sub_pol_col(elon)
insert_sub_pol_col(CathieDWood)
insert_sub_pol_col(chamath)
insert_sub_pol_col(LilMoonLambo)
insert_sub_pol_col(tyler)
insert_sub_pol_col(UniswapD)
insert_sub_pol_col(VitalikButerin)
elon.head(1) #just to check
#save df with a new name

elon.to_csv('elon_time_tweet_cleaned_btc_polar_sub_+-0.csv')
CathieDWood.to_csv('CathieDWood_time_tweet_cleaned_btc_polar_sub_+-0.csv')
chamath.to_csv('chamath_time_tweet_cleaned_btc_polar_sub_+-0.csv')
LilMoonLambo.to_csv('LilMoonLambo_time_tweet_cleaned_btc_polar_sub_+-0.csv')
tyler.to_csv('tyler_time_tweet_cleaned_btc_polar_sub_+-0.csv')
UniswapD.to_csv('UniswapD_time_tweet_cleaned_btc_polar_sub_+-0.csv')
VitalikButerin.to_csv('VitalikButerin_time_tweet_cleaned_btc_polar_sub_+-0.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11049902786779002, 'fraction_numerical': 0.009397278029812054, 'mean_word_length': 6.622222222222222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '561960', 'license': 'MIT', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1159, 'n_words': 233, 'path': 'Project/sentiment [time, tweet, cleaned, btc, polar, sub, +-0].ipynb', 'repo_name': 'q-inho/Relation-between-Bitcoin-price-and-media-tweeter-', 'size': '3086'}