Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reading .dat file and separating columns by "|" python

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 "|"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

here is one way to do it

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

or

ref.iloc[:,0]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading