0

I want to load a series of data from 6 CSV files and save them per column of the data series. As I call the Column_A, Column_B and new_Column_A, only the last output array of the data series which is the 6th CSV file is saved. Is there a possible way or function that could make me save the array of every data series of every CSV file at the end of the for loop?

Below is the code that I have so far:

for n in range(1,7):
    data = np.genfromtxt('data' + str(n) + '_.csv', delimiter=",")

    Column_A = data[35, :]
    Column_A = np.flip(Column_A ) 
    Column_A = np.reshape(Column_A , (len(Column_A )))

    new_Column_A = np.cumsum(Column_A )

    Column_B = data[0, :]
    Column_B = np.flip(Column_B ) # Reverse Array
    Column_B  = np.reshape(Column_B , (len(Column_B )))

print(Column_A)
print(Column_B)
print(new_Column_A)
tripleee
  • 175,061
  • 34
  • 275
  • 318
Ray
  • 11
  • 3
  • Is there a reason you are not using pandas? – Simon O'Doherty Apr 29 '22 at 07:29
  • the reason i dont use pandas because the data series is rowwise instead of columnwise and in the file there is a lot of data in rows that are not needed. I tried before using pandas but this comes to problem to import the data of the row-wised series into column-wise series. – Ray Apr 29 '22 at 08:09
  • You can transpose your data in pandas. – Simon O'Doherty Apr 29 '22 at 08:34

1 Answers1

0

I also strongly recommend you use pandas. It's convenient unless your csv file is tremendous. You can use

pd.read_csv

to load 6 csv files then concatenate them into a new file.

this link may help. https://pandas.pydata.org/docs/reference/index.html

Anson
  • 51
  • 3