0

I'm a very beginning programmer. I've been trying to figure this out for a few days but can't seem to wrap my head around it.

I am working with txt files (they are generated by another program). The columns contain no titles (headers?). Values are seperated by tabs.

This is the base file:

Boom    IFG : telefonische contactname (D+3)    13
Hemiksem    IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   2
Hemiksem    IFG : telefonische contactname (D+3)    7
Niel    IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   2
Rumst   IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   1

How do I properly get them into python?

I have experimented a bit. I converted the txt into a csv and in Pycharm they look exactly the same. But they are not treated the same.

If I read the txt:

data = pandas.read_csv("q658.txt", sep='\t') 
print (data)

I get :

       Boom               IFG : telefonische contactname (D+3)  13
0  Hemiksem  IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   2
1  Hemiksem               IFG : telefonische contactname (D+3)   7
2      Niel  IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   2
3     Rumst  IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)   1

If I read the csv:

data = pandas.read_csv("q658.csv", sep= '\t')
print (data)

                                                       Boom  ...  13
Hemiksem  IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)  ... NaN
Hemiksem               IFG : telefonische contactname (D+3)  ... NaN
Niel      IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)  ... NaN
Rumst     IFG : bureelgesprek/huisbezoek (Tf contact + 3 D)  ... NaN

[4 rows x 3 columns]

However, in both cases, if I set header to zero or none, I get:

ValueError: header must be integer or list of integers

How do I best get it into Python, and how do I get it to treat the first row the same as the others?

data = pandas.read_csv("q658.csv", sep= '\t', header='none')
print (data)

gives:

ValueError: header must be integer or list of integers
2
  • 1
    Can share the header=None try ? Because that is the way stackoverflow.com/questions/29287224/… Commented Jun 19, 2021 at 8:09
  • @Corralien. Thank you. I did read that, but apparently I kept overlooking it. Apologies. Commented Jun 19, 2021 at 18:10

1 Answer 1

1

You have to replace 'none' (a string) by None (object)

data = pandas.read_csv("q658.csv", sep= '\t', header=None)

Read this : https://docs.python.org/3/library/constants.html#None

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.