2017-11-27 3 views
-2

495 행의 열이 포함 된 데이터 프레임이 있습니다. jupyter 노트북에 이러한 URL을 이미지 격자로 표시하려고합니다. 데이터 프레임의 첫 번째 행이 여기에 표시됩니다. 어떤 도움을 주셔서 감사합니다. 나는 다음과 같은 방법을 시도jupyter notebook에 이미지 격자 표시

id   latitude  longitude  owner    title       url 
23969985288 37.721238 -123.071023 [email protected] There she blows! https://farm5.staticflickr.com/4491/2396998528... 

,

from IPython.core.display import display, HTML 
for index, row in data1.iterrows(): 
    display(HTML("<img src='%s'>"%(i["url"]))) 

그러나, 위의 코드의 실행하는 메시지

> TypeError       Traceback (most recent call last) 
<ipython-input-117-4c2081563c17> in <module>() 
     1 from IPython.core.display import display, HTML 
     2 for index, row in data1.iterrows(): 
----> 3 display(HTML("<img src='%s'>"%(i["url"]))) 

TypeError: string indices must be integers 
+0

이미 시도한 것을 보여주는 코드를 추가하십시오. – EFrank

+0

안녕하세요, 일부 세부 사항을 추가했습니다. – Tharindu

답변

0

에게 Jupyter 노트북에서 이미지의 눈금을 표시하는 가장 좋은 방법을 표시합니다 아마도 matplotlib을 사용하여 그리드를 생성하십시오. 을 사용하여 matplotlib 개의 축에 이미지를 플롯 할 수 있기 때문에 그리드를 생성 할 수 있습니다.

정확히 495이므로 3x165 격자를 사용하고 있습니다. 그리드의 크기를 변경하려면 자유롭게 사용하십시오.

import urllib 
f, axarr = plt.subplots(3, 165) 
curr_row = 0 
for index, row in data1.iterrows(): 
    # fetch the url as a file type object, then read the image 
    f = urllib.request.urlopen(row["url"]) 
    a = plt.imread(f) 

    # find the column by taking the current index modulo 3 
    col = index % 3 
    # plot on relevant subplot 
    axarr[col,curr_row].imshow(a) 
    if col == 2: 
     # we have finished the current row, so increment row counter 
     curr_row += 1 
+0

감사합니다. Louise, 귀하의 코드로 관리 할 수있었습니다. – Tharindu

관련 문제