UnicodeEncodeError : 'ascii'코덱은 위치 0-2의 문자를 인코딩 할 수 없습니다 : 파이썬에서 범위 (128)에없는 서수

아리 펜 쿤디

나는 단어로 데이터를 검색하여 트위터에서 데이터 마이닝을 테스트 할 때 ploblem이 있습니다.

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)이 코드에서 오류

retweet = "-filter:retweets"
query = "#Thailand" + retweet 

df = pd.DataFrame(columns = ["create_at","user","location","text", "retweet_count", "favourite_count","hashtag","follower","source"])
for tweet in tweepy.Cursor(api.search, q = query,result_type="recent", tweet_mode='extended').items(100):
     
    entity_hashtag = tweet.entities.get('hashtags')
    hashtag = ""
    for i in range(0, len(entity_hashtag)):
        hashtag = hashtag + "/" + entity_hashtag[i]["text"]
    re_count = tweet.retweet_count
    create_at = tweet.created_at
    user = tweet.user.screen_name
    source = tweet.source
    location = tweet.user.location
    follower = tweet.user.followers_count

    try:
        text = tweet.retweeted_status.full_text
        fav_count = tweet.retweeted_status.favorite_count 

    except:     
        text = tweet.full_text
        fav_count = tweet.favorite_count  
    new_column = pd.Series([create_at,user,location,text, re_count, fav_count,hashtag,follower,source], index = df.columns)
    df = df.append(new_column, ignore_index = True)

df.to_csv(date_time+".csv")

왜이 ploblem이 있습니까?

열심

utf-8scipt 시작시 시스템 기본 인코딩을 설정해보십시오 . 다음은 기본 인코딩을 utf-8로 설정해야합니다.

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관