3

I have a file which has coordinates like

1  1
1  2
1  3
1  4
1  5

and so on

There are no zeros in them.I tried using comma and tab as a delimiter and still stuck in same problem. Now when I printed the output to screen I saw something very weird. It looks like it is missing the very first line.

The output after running pa.read_csv('co-or.txt',sep='\t') is as follows

   1  1
0   1  2
1   1  3
2   1  4
3   1  5

and so on.. I am not sure if I am missing any arguments in this.

Also when I tried to convert that to numpy array using np.array, It is again missing the first line and hence the first element [1 1]

Leb
  • 15,483
  • 10
  • 56
  • 75
sridhar
  • 329
  • 4
  • 16

2 Answers2

11
df = pd.read_csv('data.csv', header=None)

You need to specifcy header=None otherwise pandas takes the first row as the header.

If you want to give them a meaningful name you can use the names as such:

df = pd.read_csv('data.csv', header=None, names=['foo','bar'])

Spend some time with pandas Documentation as well to get yourself familiar with their API. This one is for read_csv

Leb
  • 15,483
  • 10
  • 56
  • 75
-3

You can try this:

file = open('file.dat','r')
lines = file.readlines()
file.close()

and it does work.