<jupyter_start><jupyter_text>Funcion que crea el corpus de un usuario determinado<jupyter_code>def corpus_creator(user,data):
    df= data[data['screenName']==user]
    df['text_length'] = df.text.str.len()
    df[['text']] = df.text.str.lower()
    out = df[['text','screenName','created','text_length']]
    return out
corpus = corpus_creator('haddmad',data)
corpus<jupyter_output><empty_output><jupyter_text>función normalizadora de texto<jupyter_code>def word_norm(text):
  text = text.str.lower()
  text = text.replace('.', '')
  text = text.replace(',', '')
  text = text.replace('!', '')
  text = text.replace(to_replace =r'!', value='',regex=True)
  text = text.replace('á', 'a')
  text = text.replace('é', 'e')
  text = text.replace('í', 'i')
  text = text.replace('ó', 'o')
  text = text.replace('ú', 'u')
  text = text.replace('?', '')
  text = text.replace('!', '')
  text = text.replace(to_replace =r'-', value='',regex=True)
  text = text.replace(')', '')
  text = text.replace('(', '')
  text = text.replace(':', '')
  text = text.replace('/', '')
  return(text)
corpus[['text']] = word_norm(corpus.text)

corpus<jupyter_output><empty_output><jupyter_text>Funcion que calcula la polaridad y subjetividad de un tweet<jupyter_code>def sentiment_analysis(text):
    polarity = []
    subjectivity = []
    for tw in text:
        tw = TextBlob(tw)
        ann = tw.sentiment
        polarity.append(ann[0])
        subjectivity.append(ann[1])

    return polarity,subjectivity


corpus['Polarity'], corpus['Subjectivity']= sentiment_analysis(corpus.text)

pd.set_option('display.max_colwidth', -1)
corpus.iloc[2:3,0]<jupyter_output><empty_output><jupyter_text>Lemmatization<jupyter_code>#Sentence to lemmatize
sentence = "Among their university electives, the UFM students are taking a data wrangling course."

word_list = nltk.word_tokenize(sentence)
print(word_list)

# Lemmatize list of words and join
lemmatized_output = ' '.join([lemmatizer.lemmatize(w) for w in word_list])
print(lemmatized_output)<jupyter_output>Among their university elective , the UFM student are taking a data wrangling course .
{'fraction_non_alphanumeric': 0.16619452313503305, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 5.159883720930233, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '566663', 'license': 'bzip2-1.0.6', 'n_tokens_mistral': 764, 'n_tokens_neox': 748, 'n_words': 148, 'path': 'lab09/sentiment_analysis.ipynb', 'repo_name': 'dquan101/DataWrangling', 'size': '2118'}