I work with files were exported from stream twitter . but when run code then error : KeyError: 'text' on tweets['python'] = tweets['text'].apply(lambda tweet: word_in_text('python', tweet)). how to fix it ? thank everyone..!. `import re import json import string import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib tweets_data_path = '...\..\log1000.txt'
tweets_data = []
tweets_file = open(tweets_data_path, "r")
for line in tweets_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
def word_in_text(word, text):
word = word.lower()
text = text.lower()
match = re.search(word, text)
if match:
return True
return False
------------------------DataFrame--------------------------
tweets = pd.DataFrame()
------------------------------------------------------------------------
tweets['python'] = tweets['text'].apply(lambda tweet: word_in_text('python', tweet))
----------------------------------------------------------------
print (tweets['python'].value_counts()[True])`
Comment From: jreback
you should ask in StackOverflow but show a complete minimal example that is copy pastable
KeyError means that field is not found
Comment From: chienthan9x
yes , you can help me , how to fix it ?