-1

I have a data frame with 8 columns. However the rows contain several types of separators. The example below show an example of the rows that I have in my Data Frame where numbers are put between '' in order to not consider , as a separator

Germany,'3,459','12,993',96.6,'3,026,180','11,094,446',66.4,9.3

That's the code that I used to read my DataFrame

 data=pd.read_csv("Data.csv",sep=',',engine='python')

The problem is I couldn't read my Data Frame and I get an error that tells me

Expected 11 fields in line 6, saw 14
Chloe
  • 83
  • 6
  • https://stackoverflow.com/questions/48063620/pandas-read-csv-for-multiple-delimiters – Harsha Biyani Nov 26 '20 at 09:24
  • Does this answer your question? [pandas read\_csv() for multiple delimiters](https://stackoverflow.com/questions/48063620/pandas-read-csv-for-multiple-delimiters) – Bill Huang Nov 26 '20 at 09:27
  • @HarshaBiyani, BillHuang: The linked question is not relevant here. OP has one single separator here which is the comma. They just need to use *quoting* – Serge Ballesta Nov 26 '20 at 09:29
  • The op stated explicitly that *contain **several types** of separators*. Downvoted for not providing representative sample data. – Bill Huang Nov 26 '20 at 09:31
  • @BillHuang Your DV belong you, but OP provided a line of data that allows to understand the problem. Their problem is that they did not correctly understand what was happening and because of that used poor (if not confusing) wording in the question title. They talked about the single quote as a delimiter, when the CSV accepted wording is the quoting character. – Serge Ballesta Nov 26 '20 at 09:37

1 Answers1

1

A CSV file is not exactly a Dataframe, but a formatted text file. In you example, the fields are properly enclosed in quotation marks, simply they use the single quote, when the double quote is more common.

You should use the quotechar="'" parameter to declare it to read_csv:

data=pd.read_csv("hw21.csv",sep=',',engine='python', quotechar="'")
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252