Home > database >  Read Plain Text Document in pandas, only one column
Read Plain Text Document in pandas, only one column

Time:04-27

here is the photo

how can I FIX this, thank you

CodePudding user response:

You have to specify that your csv file seperator is whitespace. To do so you have to add sep='\s ' as this says that the seperator in the file is one or more spaces (Regex expression).

The better way

You have to specify delim_whitespace=True as parametes as it is faster that regex I shown you above.

So your code should be like:

pd.read_csv("beer_drug_1687_1739.txt", header=None, delim_whitespace=True)

And also I see that your first row has the names of your columns. So you have to change header=None to header=[0] to get the names of your columns.

If you have any questions feel free to ask.

  • Related