How to append rows in a pandas dataframe in a for loop?

前端 未结 5 1564
日久生厌
日久生厌 2020-11-29 16:43

I have the following for loop:

for i in links:
     data = urllib2.urlopen(str(i)).read()
     data = json.loads(data)
     data = pd.DataFrame(data.items())         


        
5条回答
  •  再見小時候
    2020-11-29 17:01

    A more compact and efficient way would be perhaps:

    cols = ['frame', 'count']
    N = 4
    dat = pd.DataFrame(columns = cols)
    for i in range(N):
    
        dat = dat.append({'frame': str(i), 'count':i},ignore_index=True)
    

    output would be:

    >>> dat
       frame count
    0     0     0
    1     1     1
    2     2     2
    3     3     3
    

提交回复
热议问题