I have a pandas data frame with shape 1725 rows X 4 columns.
date size state type
408 1 32000 Virginia EDU
...
I need to replace the state
column with the following numpy array with shape (1725, 52).
[[0. 1. 0. ... 0. 0. 0.]
...
[0. 0. 1. ... 0. 0. 0.]]
The final result should be like this:
date size state type
408 1 32000 [0. 1. 0. ... 0. 0. 0.] EDU
...
So far I tried the following based on this answer:
col = 2
df.iloc[:, col] = np_arr.tolist()
The problem is that I get this error:
dataSet.iloc[:, col] = tempData.tolist()
File "/home/marcus/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 205, in __setitem__
self._setitem_with_indexer(indexer, value)
File "/home/marcus/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 527, in _setitem_with_indexer
"Must have equal len keys and value "
ValueError: Must have equal len keys and value when setting with an ndarray