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)
3
  • Is there a reason you are not using pandas? Commented Apr 29, 2022 at 7: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. Commented Apr 29, 2022 at 8:09
  • You can transpose your data in pandas. Commented Apr 29, 2022 at 8:34

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

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.