Error while reading a csv file in pandas

Whenever i compiled the code above i get the following result :

SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3:
truncated \UXXXXXXXX escape.

import numpy as np
import pandas as pd
import matplotlib as plt
df = pd.read_csv('C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv')
df.head(10)

What can i do to solve the issue?

You can use your path as raw string, by defining r before URL:

pd.read_csv(r‘C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv’)

It should work.

1 Like

James please try below code and let me know if this works -
import numpy as np
import pandas as pd
import matplotlib as plt
df = pd.read_csv(‘C:/Users/ebene/Downloads/train_u6lujuX_CVtuZ9i.csv’)
df.head(10)

and make sure the file is present in the right path . :slight_smile:

1 Like

While loading the dataset, use forward slash("/") instead of back slash("")…

Correct syntax
df = pd.read_csv(‘C:/Users/ebene/Downloads/train_u6lujuX_CVtuZ9i.csv’)

1 Like

Send ME a copy of the dataset (the csv file ) at goel.samarth18@gmail.com. Let me try the import.

pd.read_csv(r‘C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv’)
if this doesnt work for u…
Try this:
pd.read_csv(r‘C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv’,encoding=“latin”)
df.to_csv(r‘C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv’, encoding=“utf-8”)
df = pd.read_csv(r‘C:\Users\ebene\Downloads\train_u6lujuX_CVtuZ9i.csv’)

this is bcoz sometimes there will be some encoding issue in your dataset