I need to intiialize a column in a dataframe with an empty list. I followed this closely related question. That method uses np.empty. The difference is that my lists will use the append method to add strings.
df1['Qual']=np.empty((len(df1),0)).tolist()
I get the error:
File "/usr/local/lib/python3.6/dist-packages/pandas/core/series.py", line 2582, in append
to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity
File "/usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py", line 281, in concat
sort=sort,
File "/usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py", line 357, in __init__
raise TypeError(msg)
TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid
as soon as I try to do my first append with a string (this is inside a double loop):
df1['Qual'].loc[(df1['Ship '+shipid1[index1]]=='Yes') & (df1['Pref '+str(i1+1)]==preflevel1)].append([shipcodes1[index1]])
shipcodes1 is list of strings.
How do I create such a column?