I am new to python and I am trying to add headers to the results from a text file but I keep getting the following error :
pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 4, saw 4.
After researching on this is because on the dollar amount when it is on the thousands, have a comma and pandas is looking as it would be an extra field (which is not). I would want to remove the comma from the dollar amount so when I add the headers it would not give me the error above.Any help is greatly appreciated.
Text file information:
19140E020603,$0.00,payment not received
13141W000119,$0.00,payment not received
99141V009055,$3,468.07,payment received
29141N005785,$0.00,payment not received
79141M009249,$3,468.07,payment received
15141Q005785,$127.73,payment received
Expected result:
id Amount Comments
19140E020603,$0.00,payment not received
13141W000119,$0.00,payment not received
99141V009055,$3,468.07,payment received
29141N005785,$0.00,payment not received
79141M009249,$9,398.07,payment received
15141Q005785,$127.73,payment received
Code:
import pandas as pd
fhand = open("results.txt")
result = pd.read_csv(fhand)
result.columns = ["id","Amount","Comments"]
print(result)