Add column of empty lists to DataFrame

One more way is to use np.empty:

df['empty_list'] = np.empty((len(df), 0)).tolist()

You could also knock off .index in your “Method 1” when trying to find len of df.

df['empty_list'] = [[] for _ in range(len(df))]

Turns out, np.empty is faster…

In [1]: import pandas as pd

In [2]: df = pd.DataFrame(pd.np.random.rand(1000000, 5))

In [3]: timeit df['empty1'] = pd.np.empty((len(df), 0)).tolist()
10 loops, best of 3: 127 ms per loop

In [4]: timeit df['empty2'] = [[] for _ in range(len(df))]
10 loops, best of 3: 193 ms per loop

In [5]: timeit df['empty3'] = df.apply(lambda x: [], axis=1)
1 loops, best of 3: 5.89 s per loop

Leave a Comment