2017-04-06 1 views
1

단일 플롯 n 그래프로 표시하려고합니다. n은 미국의 상태 번호입니다. for 루프가있는 단일 플롯의 여러 그래프

는 컴파일러는 사람들이 줄을 좋아하지 않는

x[j] = df['Date'] y[j] = df['Value']

=> 형식 오류 :이 특정 오류

import quandl 
import pandas as pd 
import matplotlib.pyplot as plt 

states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 
j = 0 
x = [] 
y = [] 

for i in states[0][0][1:]: 
     df = quandl.get("FMAC/HPI_"+i, authtoken="yourtoken") 
     df = df.reset_index(inplace=True, drop=False) 
     x[j] = df['Date'] 
     y[j] = df['Value'] 
     j += 1 

plt.plot(x[j],y[j]) 
plt.xlabel('Date') 
plt.ylabel('Value') 
plt.title('House prices') 
plt.legend() 
plt.show() 
+0

첫째는, 당신은 정의되지 않은'x'와'y' 작업 차트를 얻을 수 있습니다. 그래서 어딘가에'x = []; y = []'. 둘째, j 번째 단계에서 x [j]가 실제로 존재하지 않기 때문에 새 항목을 추가해야합니다. x.append (...)를 사용하십시오. 가능한 경우 확실하지 않은 데이터 프레임 목록 작성에 관한 추가 문제가있을 수 있습니다. – ImportanceOfBeingErnest

+0

도움을 주셔서 감사합니다, 다른 것들에 대해 검색 할 것입니다 – louisdeck

답변

1

문제를 첨자에되지 않는다 'NoneType'객체는 당신이 inplace 인수를 사용하는 것입니다 변수 df에 다시 할당합니다. 내부 인수가 True와 같으면 반환 값은 None입니다.

print(type(df.reset_index(inplace=True, drop=False))) 
NoneType 

print(type(df.reset_index(drop=False))) 
pandas.core.frame.DataFrame 

사용 중 inplace=True 및 DF로 다시 지정하지 : 올바른 위치에 대한

df.reset_index(inplace=True, drop=False) 

또는 사용 기본 = 거짓과 다른이 있습니다

df = df.reset_index(drop=False) 

df라고 다시 변수에 지정 논리 오류가 여기에 있습니다.

편집 (테스트를 위해 20 제한)

for i in states[0][0][1:20]: 
     df = quandl.get("FMAC/HPI_"+i, authtoken="yourtoken") 
     df.reset_index(inplace=True, drop=False) 
     plt.plot('Date','Value',data=df) 


# plt.plot(x[j],y[j]) 
plt.xlabel('Date') 
plt.ylabel('Value') 
plt.title('House prices') 
plt.show() 

enter image description here

+0

정말 고마워요 설명을 주셔서 감사합니다. 며칠 전부터 Python과 그 라이브러리를 시작하면서 개선해야 할 부분이 있습니다. D – louisdeck

+0

대단합니다. –

관련 문제