0

I need to read data from a .dat file, using Python, that is in the following format:

column_id value column_id value column_id value .....

column_id value column_id value column_id value .....

. . .

and so on.

Each new line is a single sample. Ideally, I want to read this into a Dataframe such that - each new line corresponds to a row and values will be inserted at corresponding 'column_id' in the row.

I did the mapping by looping over the rows, and individual column ids & values in each row, but it is taking a lot of time.

I am looking for help with getting a better, more efficient way of doing it. Probably, there is some library that does this already but I am unaware of it.

Edit:

For example,

12 1 13 3 36 8 39 2 .....

34 0 57 3 78 4 90 5 .....

. . .

So, Dataframe should have

value = 1 for row = 0 and column = 12 &

value = 3 for row = 0 and column = 13 &

vlaue = 0 for row = 1 and column = 34

and so on

jjPotter
  • 3
  • 2
  • Possible duplicate of [Difficulty importing .dat file](https://stackoverflow.com/questions/27413843/difficulty-importing-dat-file) – D.Sanders Mar 27 '19 at 17:54
  • @D.Sanders No, this is not what I am looking for. Added an example for more clarity. – jjPotter Mar 27 '19 at 18:09

0 Answers0