'invalid decimal literal when importing csv via pandas

not sure if something has changed within pandas but all of a sudden I am unable to import my .csv file using pd.read_csv due to the following error:

PS C:\Users\Admin\Documents\GitHub\REPLete> python cust.csv UK
  File "C:\Users\Me\Documents\GitHub\REPLete\cust.csv", line 61

97,1652223600,17927711,Paperclips,1w
                                  ^
SyntaxError: invalid decimal literal

This occurs on the first occurrence of where there is both [a-z] and [0-9] in a single field. Almost as if Pandas is trying to convert it into a Decimal but it can't because there is a non-decimal character...

The exact code used is as follows:

df = pd.read_csv('cust.csv')

The first few lines of the CSV are as follows:

Completed,Action Required,Addr1,Addr2,Addr3,Addr4,Addr5,Postcode,DT_Set,Pri,DT_Due,Tel,NOTES:,NHS_Org,Company,Contact_Email,Billing_Email,Contact_FirstName,Contact_LastName,Interested in Demo,Date Scheduled,Time of Demo,Lead name
,,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,XYZ XYZ,,,,1279621900,,RP0005,New Road Surgery,[email protected];[email protected],[email protected];[email protected],Jeremy,Fisher,SPEAKING TO MICHAEL 10y,,,
,,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,XYZ XYZ,1649075159.0,97.0,1964646000.0,1933234900,,RP0006,Long Road Medical,[email protected],[email protected],Marjorie,Stewart-Baxter,,,,
,,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,Xyz Xyz,XYZ XYZ,1648635737.0,97.0,1964214000.0,2476674123,,RP0008,Rusty Spoon Medical Centre,[email protected],[email protected];[email protected];[email protected],Hubert,Cumberdale,ALREADY GOT IT,,,

How can I force read_csv to interpret everything as a string / object? I will selectively cast the fields using df.astype that I need to be Integer/Float etc.

Hope someone can help!

Cheers, Luke.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source