0

Scenario: As the question title implies I am trying to convert a pandas dataframe to a numpy array. The dataframe has normal 2d data, just numbers. From other questions here in SO (such as Strange error during conversion from Panda Dataframe to numpy array Pandas series to numpy array conversion error Spyder Python "object arrays are currently not supported") and from the documentation I wrote the code. But apparently my problem is slightly different from those questions:

Problem: The code runs normally, and I can see the array in the variable explorer, but when I try to open it it yields:

Object arrays are currently not supported.

Question: What am I doing wrong? How can I fix it?

Obs: I am running python 2.7 on Spyder.

Code:

import pandas as pd
import numpy as np


df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
inp_file = df 
compofile ="Co"
yieldfile = "Y"
maturityfile = "T"
countryfile ="Cou"


'#importing excel files

'co1 = pd.read_excel(inp_file,sheetname=cofile)
'y1 = pd.read_excel(inp_file,sheetname=yfile)
'm1 = pd.read_excel(inp_file,sheetname=mfile)
'cou1 = pd.read_excel(inp_file,sheetname=coufile)

co2 = inp_file.as_matrix()
7
  • As we don't have this .xlsx file read in your code, can you provide a minimal reproducible example? Commented Feb 9, 2018 at 14:16
  • @Alfe Altered to include a random pd dataframe that can be replicated. result is the same. Commented Feb 9, 2018 at 14:24
  • I can't replicate your problem. Could you restart Spyder and try again. Commented Feb 9, 2018 at 14:34
  • @KRKirov Just did that and also restarted the pc. Same result. Commented Feb 9, 2018 at 14:37
  • 2
    You can just call .get_values() on your pandas DataFrame. That will return the 2D numpy array of the values therein. .as_matrix() works for me as well. I guess you have a different problem. I suggest you try to reproduce your problem yourself in a minimal system (Python interpreter on command line, etc.) without all your surrounding system stuff. Commented Feb 9, 2018 at 14:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.