-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
ReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeUsage Question
Description
I'm trying to add a column to an existing dataframe. The dataframe can be empty (0 rows) but I want the column to be added anyway.
import pandas as pd
import numpy as np
df = pd.DataFrame(index=np.arange(4))
df.loc[:,'col'] = 42 # this works fine!
df = pd.DataFrame(index=np.arange(0)) # empty dataframe
df.loc[:,'col'] = 42 # ERROR: ValueError: cannot set a frame with no defined index and a scalar
df['col'] = 42 # this works fine but seems deprecated
pd.__version__ is '0.15.2'
Metadata
Metadata
Assignees
Labels
ReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeUsage Question