JSON 파일을 데이터 프레임에 맞추려고합니다.JSON 파일을 pandas 데이터 프레임에 맞추는 중 오류가 발생했습니다.
fname = 'python.json'
with open(fname, 'r') as f, open('sentiment.json', 'w') as s:
for line in f:
tweet = json.loads(line)
# Create a list with all the terms
tweet_words = tweet['text']
output = subprocess.check_output(['curl', '-d', "text=" + tweet_words.encode('utf-8'), 'http://text-processing.com/api/sentiment/'])
s.write(output+"\n")
그것은 기록하는 text-processing.com의 API에서 요청 'sentiment.json'출력에 : 내 현재 도청 코드는 다음과 같은 방법을 통해 JSON 파일을 만듭니다. 그때 사용하여 JSON을로드 :
def load_json(file, skip):
with open(file, 'r') as f:
read = f.readlines()
json_data = (json.loads(line) for i, line in enumerate(read) if i%skip==0)
return json_data
을 그리고 사용 dataframe를 구성 :
sentiment_df = load_json('sentiments.json', 1)
data = {'positive': [], 'negative': [], 'neutral': []}
for s in sentiment_df:
data['positive'].append(s['probability']['pos'])
data['negative'].append(s['probability']['neg'])
data['neutral'].append(s['probability']['neutral'])
df = pd.DataFrame(data)
오류 :에 ValueError : 없음 JSON 객체가 내가 몇 가지 관련 질문을 통해 찾아
를 디코딩 할 수 없었다 WoodrowShigeru의 답변 here을 기반으로, 첫 번째 코드 블록에서 'utf-8'로의 인코딩과 관련이 있다고 생각됩니다.누구든지 좋은 수정 사항을 알고 있습니까? 아니면 적어도 몇 가지 지시 사항을 제공합니까? 고마워요!
편집 한