Lets say I want to create and fill an empty dataframe with values from a loop.
import pandas as pd import numpy as np years = [2013, 2014, 2015] dn=pd.Data
As far as I know you should avoid to add line by line to the dataframe due to speed issue
What I usually do is:
l1 = [] l2 = [] for i in range(n): compute value v1 compute value v2 l1.append(v1) l2.append(v2) d = pd.DataFrame() d['l1'] = l1 d['l2'] = l2