1

I have a set of csv files that I am trying to concat. I am having issues that the concatenated file does not apply the comma separators to the content. Given below is the code:

##Location where the csv files are located
updatedfiles = glob.glob(LOCAL_PATH2 + "/*.csv")

#Applying comma separator to the concatenated output
df_v1 = [pd.read_csv(fp, sep=',', delim_whitespace=True).assign(FileName=os.path.basename(fp)) for fp in updatedfiles]

Could anyone guide me on this. Thanks

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

1 Answers1

1

I believe need to remove delim_whitespace=True, because 2 separators , and whitespace. If need both sep='\s+|,' should working or parameter skipinitialspace=True it need remove trailing whitespaces.

read_csv:

delim_whitespace : boolean, default False

Specifies whether or not whitespace (e.g. ' ' or '\t') will be used as the sep. Equivalent to setting sep='\s+'. If this option is set to True, nothing should be passed in for the delimiter parameter.

Community
  • 1
  • 1
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252