Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am trying to load tweets data, but some of the tweets are intentionally damaged and will not parse properly. You will need to

Hi, I am trying to load tweets data, but some of the tweets are intentionally damaged and will not parse properly. You will need to store these damaged tweets in a separate error file. For tweets that could not parse, write them into errors.txt file (do not ignore). My question is I don't know how to write them into txt file correctly. My syntax is as below:

import json for tweet in allTweets: try: tdict = json.loads(tweet.decode('utf8'))

..... except ValueError:

newtweet=tweet.decode('utf8') outfile=open("errors.txt","w")

outfile.write(newtweet)

outfile.close()

print (tweet)

in terms of the line: outfile.write(newtweet), I get the EncodeError message:'ascii' codec can't encode characters in position 467-468: ordinal not in range(128)

How to correct that? what's my problem?

Please ignore the incorrect indentation in my syntax, I don't know why I cannot edit the format. Thanks in advance!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions