1

I am trying to read a CSV file in python(google colab). Please, find attached the file in the following link: https://github.com/LeGentilHomme/CSV-FILE/blob/4b69985482e59906b64a540b9c0d0a7fce31a37e/exportIndicateurs(7).csv In fact, this time series data in French contains semi-columns and the variables are contained in the rows, while the time or dates are in the columns. After multiple trials, what I get is a table with all the values and semi-columns in one column, and the rest of the cells shows NaN values. I have tried the following code:

df=pd.read_csv("exportIndicateurs(7).csv", delimiter=';',header=1, encoding='latin-1')
df

but I get the results that I have attached in the following pictures.

Thank you in advance for your help.Result picture

JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • Does this answer your question? [Skip rows during csv import pandas](https://stackoverflow.com/questions/20637439/skip-rows-during-csv-import-pandas) – JosefZ Mar 31 '23 at 19:47

2 Answers2

2

Use (-*;) as a regex separator in read_csv :

gh_link = "https://raw.githubusercontent.com/LeGentilHomme/CSV-FILE/4b69985482e59906b64a540b9c0d0a7fce31a37e/exportIndicateurs(7).csv"

df = pd.read_csv(gh_link, sep="-*;", header=2, engine="python")

Output:

enter image description here

Timeless
  • 22,580
  • 4
  • 12
  • 30
-1

Please try "sep" instead of "delimiter":

df = pd.read_csv("exportIndicateurs(7).csv", sep=';',header=1, encoding='latin-1')
print(df)
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • 1
    `sep` is an alias for `delimiter`. See [pandas.read_csv](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html). – Mark Tolonen Mar 31 '23 at 19:32
  • I have tried it but it doesn't work. It seems like the code cannot make the distinction between the values and the variables, thus putting all of them in the same column. In addition, in French, the thousands are marked by a coma instead of a dot. I think might be one of the issues. – Prototype51 Mar 31 '23 at 19:45