0

I currently have a .npy file and I would like to store the data it contains in a variable in order to convert it to a dataframe.

I tried using the following:

data_array=np.load('Jason1Data_Full_East_West.npy')
df = pd.DataFrame(data_array)

However my dataframe came out as a single column. How do I save the data in a format where the columns are clearly separated with now square brackets around the rows?

Below is the result I am currently getting. enter image description here

3
  • 2
    You must provide a minimal reproducible example for us to diagnose the problem. Commented Aug 20, 2017 at 17:36
  • It looks like your data was never structured properly in the first place. Commented Oct 5, 2017 at 17:32
  • It was sent to me. Is there a way to get it in the format I want? Commented Oct 5, 2017 at 17:34

1 Answer 1

1

Even your question is not clear. You can try the following:

path = .../Jason1Data_Full_East_West.npy
data = np.load(path)

And then you need to convert it to dataframe as the following:

pd.DataFrame({'Data':data.tolist()})
Sign up to request clarification or add additional context in comments.

4 Comments

Jason != JSON. Jason is also a common male name.
Sorry Arya, I didn't fully understand the question. Now I corrected the answer. please comment :)
Don't forget quotes for the path. Is tolist necessary? What about pd.DataFrame(data)?
I have edited the question a bit because I have encountered this situation again. Could you guys provide me with some assistance please?

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.