0

I am attempting to convert 5 dataframes to numpy arrays in a loop.

df = [df1, df2, df3, df4, df5]

for index, x in enumerate(df):
  x = x.to_numpy()

print(type(df3)) still gives me pandas DataFrame as the output.

4
  • sorry your code does not make sense. you iterate through an array name, df. and then what do you do with index and x? Commented May 25, 2020 at 1:30
  • 1
    I'd recommend reading some introductory documentation first. Understanding variables and scopes can be tricky in the beginning, and jumping straight to pandas without having these concepts well-absorbed might not be the best idea ;) Commented May 25, 2020 at 1:33
  • 1
    np.array([x.to_numpy() for x in df]) Commented May 25, 2020 at 1:55
  • there are 5 DataFrames. I want to convert each of them to an numpy array in one loop and save it Commented May 25, 2020 at 2:10

1 Answer 1

1

This dose not save into the environment

for index, x in enumerate(df):
  df[index] = x.to_numpy()

Then you do

df[0]
Sign up to request clarification or add additional context in comments.

1 Comment

is there a way to convert df1, df2, df3 DataFrames to arrays? Your method works as well, but I have to call them from the list df now

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.