Home > Blockchain >  why can't i import this file into python(pandas) using pd.read_csv( ) command line
why can't i import this file into python(pandas) using pd.read_csv( ) command line

Time:12-11

i get an error message anytime i try to import this file into python using the pandas library, it works fine for some other csv files this same file, I easily import using Numpy as in

np.genfromtxt() ```

with the delimiter set.
why this difference

raw_data_np=np.genfromtxt("Loan-data.csv", delimiter=';')

raw_data_np

this imports the file but this 2nd code doesn't:
pd.read_csv('Loan-data.csv')
 i get a unicode decode error with a really long list of lines underneath

CodePudding user response:

Because the default value of the sep parameter (alias delimiter) in pandas.read_csv is the comma (,) and not the semi-colon (;). You need to specify this as you did with numpy.genfromtext.

Try this :

pd.read_csv('Loan-data.csv', sep=';')

CodePudding user response:

Try to use this

pd.read_csv(r'C:\Users\XXXXX\XXXXX\Loan-data.csv',sep=";")

in place of 'C:\Users\..........' copy your file location and paste it here so you did not get any unicode error

  • Related