4

I can't find a way to control the output of each column dataframe. From the following code:

df.to_csv('dfnc.txt', 
        sep=' ', 
        float_format='%.8f',
        cols=['cycle','passs','ip','lon','lat'],
        index=False)

I'm getting this:

1.00000000 1.00000000 543.00000000 23.15881870 -64.70485950
1.00000000 1.00000000 544.00000000 23.10356160 -64.64569150
1.00000000 1.00000000 545.00000000 23.04852510 -64.58650550
1.00000000 1.00000000 546.00000000 22.99370760 -64.52730150
1.00000000 1.00000000 547.00000000 22.93910770 -64.46807990

And I want this:

1 1 543 23.15881870 -64.70485950
1 1 544 23.10356160 -64.64569150
1 1 545 23.04852510 -64.58650550
1 1 546 22.99370760 -64.52730150
1 1 547 22.93910770 -64.46807990

Many thanks for the help.

1 Answer 1

3

I think you can just convert the 1st to the 3rd columns to int64 before writing the CSV file (if you check the .types, I am sure they are all float64):

df[['cycle', 'passs', 'ip']]=df[['cycle', 'passs', 'ip']].astype(int64)
Sign up to request clarification or add additional context in comments.

2 Comments

You're right about .types, they were all float64. Your solution worked like a charm! Thanks a lot for the help!
What if you want to control the decimal places in the float output?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.