0

I was wondering if anyone had any suggestions on how to do the following: I have multiple files: R1.csv, R2.csv and R3.csv Each file has the following content in the same format: For example: R1.csv:

              data_label pt1 pt2
              DATA00_A1 1 2
              DATA01_A1 11 22
              DATA02_A1 111 222

R2.csv:

              data_label pt1 pt2
              DATA00_A2 1 2
              DATA01_A2 11 22
              DATA02_A2 111 222

So far to access these files and retrieve the data I have been using pandas:

import pandas as pd
dfObject=pd.read_csv('R1.csv',delimiter=' ')
labels=dfObject.data_label
datax=dfObject.pt1
datay=dfObject.pt2

But now I need to have all the data in one file. For example:

Rall.csv:

              data_label pt1 pt2
              DATA00_A1 1 2
              DATA01_A1 11 22
              DATA02_A1 111 222
              DATA00_A2 1 2
              DATA01_A2 11 22
              DATA02_A2 111 222

I am not sure how to begin, so I would appreciate your suggestions, thanks!

Adhun Thalekkara
  • 713
  • 10
  • 23
  • 1
    https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe – Dishin H Goyani Jul 16 '20 at 16:49
  • 1
    Try `pd.concat(R1, R2)` . If you have more than two it is better to append all to a list and combine them after. – XXavier Jul 16 '20 at 16:50

1 Answers1

0

Try this:

import pandas as pd

R1=pd.read_csv('R1.csv',delimiter=' ')
R2=pd.read_csv('R1.csv',delimiter=' ')

Rall = {}

for x in R1.columns:
    Rall[x] = list(R1[x])+list(R2[x])

Rall = pd.DataFrame(Rall)
Rall.to_csv("Rall.csv", sep=" ")
print(Rall)