This question is probably very simple, but I seem to be having trouble creating a new column in a dataframe and filling that column with a numpy array. I have an array i.e. [0,0,0,1,0,1,1] and a dataframe that has the same number of rows as the length of that array. I want to add a column and I have been doing this:
df['new_col'] = array
however I get the following warning error:
A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
I tried to do df.loc[:,'new_col'] = array
but get the same warning error. I also tried:
df.loc['new_col'] = pd.Series(array, index = df.index)
based on a different answer from a question a different user asked. Does anyone know a "better" way to code this? Or should I just ignore the warning messages?