Kevin Nash
Kevin Nash

Reputation: 1561

Data not applying separator to csv file while concatenating in Pandas

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

Upvotes: 1

Views: 126

Answers (1)

jezrael
jezrael

Reputation: 862511

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.

Upvotes: 1

Related Questions