2

I have a data like that;

print(df_3d20)

          Open Rates              Close Rates
Date      col_1   col_2   col_3   col_1   col_2   col_3
2020-1-1   0.0     0.0     0.0     0.0     0.0     0.0
2020-1-2   0.0     0.0     0.0     0.0     0.0     0.0
2020-1-3   0.0     0.0     0.0     0.0     0.0     0.0
2020-1-4   0.0     0.0     0.0     0.0     0.0     0.0

It is perfect formation for me. I can take easily whatever I want and I can see. But unfortunately I have a problem when I'm saving this.

I'm saving like that:

df_3d20.to_csv("BIST100_2020.csv")

and when i try open it again data comes like this:

          Open Rates OpenRates.1 OpenRates.2  Close Rates CloseRates.1 CloseRates.2      
Date      col_1       col_2      col_3        col_1       col_2        col_3
2020-1-1   0.0        0.0        0.0          0.0     0.0     0.0
2020-1-2   0.0        0.0        0.0          0.0     0.0     0.0
2020-1-3   0.0        0.0        0.0          0.0     0.0     0.0
2020-1-4   0.0        0.0        0.0          0.0     0.0     0.0

But I want to import it like the first formation I have shown. So, what should I do about importing and exporting 3d pandas dataframes?

Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42

2 Answers2

0

So instead of exporting and importing a 3 dimensional dataframe, import/export a 2d one, and then you can do what this question does.

Pythoneer
  • 319
  • 1
  • 16
0

Use a 2D array. You can use the Numpy module and use its np.loadtxt() function which returns the data into a 2D array. Or you can use the open() function and pass the given CSV file as an argument to the DictReader(). For example:

##### Import the python CSV module

import csv

##### Create a python file object in read mode for the `baby_names.csv` file: 

csvfile = open('baby_names.csv', 'r')

##### Loop over a DictReader on the file

for row in csv.DictReader(csvfile):
###### your code
Julia Meshcheryakova
  • 3,162
  • 3
  • 22
  • 42