-2

How do I correctly read a CSV with currency symbols? I tried many encodings

df = pd.read_csv('file.csv', encoding="windows-1252")
df
     € discount  €price
0      1            2

Expected Output:

df
     € discount  €price
0      1            2

asd
  • 1,245
  • 5
  • 14
  • see this: https://stackoverflow.com/questions/59334400/not-able-to-read-currency-symbol-from-the-cell-using-pandas-python – Abdelrahman Feb 26 '21 at 13:50

2 Answers2

2

If you aren't sure of the encoding, do this:

with open("my_data.csv", 'rb') as rawdata:
    result = chardet.detect(rawdata.read(10000))

This will return information about the file, including it encoding. Then:

df = pd.read_csv('my_data.csv', encoding="the encoding you found")
0

Given the following csv file

€ discount,€ price
1,2

using just pandas.read_csv works fine for me:

import pandas as pd

pd.read_csv("data.csv")
€ discount € price
1 2
Oxbowerce
  • 430
  • 5
  • 14