-1

I am trying to concat multiple csv files into 1 file using python3. How can i do this. All the csv files in the same folder. When i used glob it gives me an error.

import glob
import csv

newfile = glob.glob('C:\Users\perera\Desktop\Machine Learning\RYU\data\dataset_1\*.csv')

and the error is

(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

what is the problem here

2 Answers2

3

\U within a string literal is interpreted as an escape sequence. Use a raw literal to avoid parsing of escape sequences.

newfile = glob.glob(r'C:\Users\perera\Desktop\Machine Learning\RYU\data\dataset_1\*.csv')
Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56
-1
import pandas as pd;
import os;

frame = pd.DataFrame()
df = pd.concat([pd.read_csv(f'dir/{f}') for f in os.listdir('dir') 
if f.endswith('.csv')])
Rohit.007
  • 3,414
  • 2
  • 21
  • 33