Home > Mobile >  Reading .dat file and separating columns by "|" python
Reading .dat file and separating columns by "|" python

Time:10-04

I am trying to read the 0th column in my .dat file in python. The file column is split by "|".

For example:

lalaland   |   La2   |  It's a good day   |   Blah

I have the following to read the data and split columns by "|"

ref = pd.read_csv('DataBase.dat',sep="|")

The output is:

lalaland\t\t\t  ...                         \tBlah
0    happy\t\t\t\t  ...                       \tDescription A
1    good\t\t\t\t  ...                       \tDescription B

When I try to access the data via ref[0:] The 1st row of data is outputted instead of the 0th column.

How can I access the data only in the 0th column and put it in an array?

CodePudding user response:

here is one way to do it

ref.loc[:,ref.columns[0]]

or

ref.iloc[:,0]

  • Related