0

Which one is faster?

first approach: assigning values to an empty dataframe

df = pd.DaraFrame(index = range(5), columns=['A','B'])
for i in range(5):
   df.iloc[i] = i , i*i

second approach: appending values to dataframe

df = pd.DaraFrame(columns=['A','B'])
for i in range(5):
   df.iloc[i] = i , i*i
arash
  • 161
  • 13
  • 1
    df['A'],df['B']=df.index,df.index**2 – BENY Oct 25 '18 at 14:00
  • 1
    This is something you can test yourself with [`timeit`](https://docs.python.org/2/library/timeit.html), though neither of those are actually efficient ways to perform that calculation as Wen points out. – ALollz Oct 25 '18 at 14:24

1 Answers1

1

You can find it yourself using the time module.

See this link to see how to use calculate execution time:

How do I get time of a Python program's execution?

Destiny
  • 141
  • 7