What\'s the easiest way to add an empty column to a pandas DataFrame object? The best I\'ve stumbled upon is something like
DataFrame
df[\'foo\'] = df.ap
I like:
df['new'] = pd.Series(dtype='your_required_dtype')
If you have an empty dataframe, this solution makes sure that no new row containing only NaN is added.
NaN
Specifying dtype is not strictly necessary, however newer Pandas versions produce a DeprecationWarning if not specified.
dtype
DeprecationWarning