Reading file with delimiter using pandas

I have a data in a file I dont know if it is delimited by space or tab

Data In:

id              Name                                                                                year    Age Score 

123456          ALEX BROWNNIS VND                                                                        0      19     115
123457          MARIA BROWNNIS VND                                                                       0      57     170
123458          jORDAN BROWNNIS VND                                                                      0      27     191

I read it the data with read_csv and using the tab delimited

df = pd.read_csv(data.txt,sep='\t')

out:

     id           Name                                                                                year  Age  Score 
0          123456  ALEX BROWNNIS VND                             ...                                     0   19     115
1          123457  MARIA BROWNNIS VND                            ...                                     0   57     170
2          123458  jORDAN BROWNNIS VND                           ...                                     0   27     191

There is a lot of a white spaces between the column. Is is correct the tab delimiter? and when I try to process the column name, I gotkey error so I basically think the fault is use of /t.
What are the possible way to fix this problem?



Read more here: https://stackoverflow.com/questions/68470967/reading-file-with-delimiter-using-pandas

Content Attribution

This content was originally published by Prestige at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: