Skip to content
Prev 353071 / 398498 Next

Reading some csv files from different folders and add the name of each files to the first column of files

I have 600 folders in which there are 3 csv files. The name of folders are
as follows: EA_aa, EA_bb, EA_cc, EA_dd,....

In each folder there are 3 csv files:
in folder EA_aa there are:
  EA_sing_aa.csvqwerty
  EA_ska_aa.csv
  EA_tat_aa.csv

In folder EA_bb:
  EA_sing_bb.csv
  EA_ska_bb.csv
  EA_tat_bb.csv
...

I need to read all the same kind of files (for example sing files) in one
dataframe but before that I should add a column to each files with the name
of file as a row names!

So in output I should have just 3 csv files such as
EA_sing.csv: (rbind all EA_sing_*.csv file)
EA_ska.csv: (rbind all EA_ska_*.csv files)
EA_tat.csv: (rbind all EA_tat_*.csv files)

And in each file the first column should be added as row names which
containing the file name! So the format will be as follow:
EA_sing.csv:
1st column   2nd column  3rd column
   aa                    yhhh                ghj
   aa                     k ki                   Fyh
   bb                     k ki                   vgd
   bb                     k gki                  Fyh
   bb                    k reci                  Fyh
   cc                     k hcd                  hyd
   dd                     lmb                     Fyh

EA_ska.csv:
1st column   2nd column  3rd column
   aa                    yhhh                ghj
   aa                     k ki                   Fyh
   bb                     k ki                   Fyh
   cc                     k gki                  Fyh
   cc                     k reci                  oki
   cc                     k hcd                  Fyh
   dd                     lmb                     dsf

EA_tat.csv:
1st column   2nd column  3rd column
   aa                    yhhh                ghj
   aa                     k ki                   Fyh
   bb                     k ki                   Fyh
   cc                     k gki                  Fyh
   cc                     k reci                  oki
   dd                     k hcd                  Fyh
   dd                     lmb                     dsf

Would you please help me how to can I do that?
Thanks
Message-ID: <CAMqbV1CXN0=R+HxmaYS40sMymGdbhDQK1V+n5bHmBPgBr3M2Yg@mail.gmail.com>
In-Reply-To: <CAMqbV1AoHGRSa_EHH5_oqVWvoKn=6R8y8Xg9P5HzpcpTe=PCmA@mail.gmail.com>