'Unable to read the tsv data using pandas

I have verified the encode of .tsv file. But while reading the .tsv file using pandas dataframe, I am getting the error like the below error.

Below is endcode i have found for my .tsv file :

<_io.TextIOWrapper name='C:\\Users\\xxxx\\xxxxx\\sample.tsv' mode='r' encoding='cp1252'> 

But as a result, using pandas to read the dataframe i am getting the below error :

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 16: character maps to <undefined> 

Here is the code snippet i used :

read_tsv = 
       pd.read_csv('C:\\Users\\xxxx\\xxxx\\sample.tsv',sep='\t', encoding='cp1252')
                   
print(read_tsv.head())

Could you please help me for this error.



Solution 1:[1]

Try this

pd.read_csv(r'C:\\Users\\xxxxx\\xxxxx\\sample.tsv', skiprows=2, encoding = 'utf-8')

Anyway you should try all options using different separators (like ";" or "," or "\n") But if you can open this file in another program and take a screenshot then show me how it looks

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 vovakirdan