3sm1r
3sm1r

Reputation: 530

Reading greek letters from a file

I have a .csv file with a certain number of columns. One of the column has several values called Δ (Greek letter Delta).

I tried to print the letter and I was successful:

print u'\u0394'

properly returns the Greek letter.

However, if I try to select the rows of the file containing Δ in the column called 'column', using

file=pd.read_csv('filename.csv',sep=';')
print file[file['column']==u'\u0394']

I find myself with an empty list, even though I know that some rows do have Δ in that column.

What am I doing wrong?

Upvotes: 1

Views: 2069

Answers (1)

GPhilo
GPhilo

Reputation: 19123

You must add encoding='utf-8' to read_csv, because python 2 does not default to unicode strings (and byte strings can't deal with Delta). You don't get anything because Pandas silently ignores the failure when reading the string:

file=pd.read_csv('filename.csv', sep=';', encoding='utf-8')

Upvotes: 3

Related Questions