-1

I have 4 folders and every folder has like 500 CSV files. I want to collect all the names of the CSV files in one CSV for visualization by python.

All CSV files have just one column. How can I split to multi columns the rows like this [2016 05 30:t5-45+09], (there is no comma here and no space)

I wanna put all of the information in column like:

year | month | day 
2016 | 05  | 30

columns_name =['col1 ','col2','col3']
read=pd.read_csv("file path", header=None, names=columns_name)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
sarahkh
  • 11
  • 3

1 Answers1

0

You can list down the directories path and read all files inside them using os.listdir() as described in here.

As for splitting the the column into 3, first you have to iterate each rows of the csv using csv.reader as described here. Then for each row, convert them to 3 parts and write them back to the new csv. You can do something like this for the conversion:

import re

row = ['2016 05 30:t5-45+09']
res = re.search('(\d{4}) (\d{2}) (\d{2}):.*', row[0], re.IGNORECASE)
print(res.groups()) # ('2016', '05', '30')

You can find example on how to write them back to csv in the same doc.

Community
  • 1
  • 1
Yohanes Gultom
  • 3,782
  • 2
  • 25
  • 38