Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an np.array as a column in a pandas.DataFrame

I have a pandas data frame and a numpy nd array with one dimension. Effectively it is a list.

How do I add a new column to the DataFrame with the values from the array?

test['preds'] = preds gives SettingWithCopyWarning And a warning:

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

And when I try pd.DataFrame({test,preds}) I get TypeError: unhashable type: 'list'

like image 236
DolphinGenomePyramids Avatar asked Jun 28 '15 18:06

DolphinGenomePyramids


1 Answers

Thanks to EdChum the problem was this

test= DataFrame(test)
test['preds']=preds

It works!

like image 64
DolphinGenomePyramids Avatar answered Sep 21 '22 23:09

DolphinGenomePyramids