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()
DGMS89
  • 1,507
  • 6
  • 29
  • 60
  • As we don't have this `.xlsx` file read in your code, can you provide a [mcve]? – Alfe Feb 09 '18 at 14:16
  • @Alfe Altered to include a random pd dataframe that can be replicated. result is the same. – DGMS89 Feb 09 '18 at 14:24
  • I can't replicate your problem. Could you restart Spyder and try again. – KRKirov Feb 09 '18 at 14:34
  • @KRKirov Just did that and also restarted the pc. Same result. – DGMS89 Feb 09 '18 at 14:37
  • I am running python-3.6 but am positive that I have had the same problem with Spyder as you. Can you at least print your numpy array? – KRKirov Feb 09 '18 at 14:41
  • @KRKirov I can do all operations with it and print it in the kernel, just cannot open it from the variable explorer. – DGMS89 Feb 09 '18 at 14:43
  • 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. – Alfe Feb 09 '18 at 14:44

0 Answers0