2

I am trying to append a numpy array into an already existing dataframe.

df_train = pd.DataFrame()
sk_train = sklearn_representation_train.toarray()

The shape of both dataframe and sk_train is:

sk_train
-> array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])

sk_train.shape
-> (95851, 2000)

df_train.shape
-> (95851, 9)

How do convert the sk_train numpy array to dataframe and concatenate it to df_train?

4
  • Have you looked at DataFrame.append or DataFrame.concat depending on how you want things to line up? Commented Dec 30, 2017 at 14:00
  • x = np.zeros((100,200)); y = np.zeros((100, 90)); pd.concat([pd.DataFrame(x),pd.DataFrame(y)]) Commented Dec 30, 2017 at 14:05
  • @skrubber I am facing memory error while performing this operation. Commented Dec 30, 2017 at 14:18
  • stackoverflow.com/questions/44715393/… Commented Dec 30, 2017 at 14:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.