writing and reading a csv file

8 views
Skip to first unread message

Gijs Dekkers

unread,
Dec 16, 2020, 6:04:51 AM12/16/20
to liam2-users

Dear all,

I have an issue with reading and writing csv files. In a first process, I produce a csv-file

                - csv(al_f_active_pop, fname = '../../output/temp/al_f_active_pop.csv')
See the file in attachment
al_f_active_pop looks like this in the console
>>> al_f_active_pop

agegroup_work |        |        |        |        |        |        |        |        |       |      |     
           15 |     20 |     25 |     30 |     35 |     40 |     45 |     50 |     55 |    60 |   65 |   66
        37.17 | 196.25 | 295.65 | 312.12 | 305.00 | 327.52 | 332.00 | 300.48 | 226.72 | 96.20 | 4.11 | 1.97
so that appears correct.

Now the issue starts when  I read the attached file back
>>> (load('../../output/temp/al_m_active_pop.csv', type = float)[:])
 - reading C:\usr\midas\output\temp\al_m_active_pop.csv

agegroup_work |       |        |        |        |        |        |        |        |        |        |      |     
           15 | 50.20 | 221.48 | 313.76 | 343.72 | 341.36 | 371.39 | 386.37 | 360.51 | 282.32 | 137.33 | 7.00 | 4.11

This is obviously not correct. What am I doing wrong?

Thanks

Gijs
al_f_active_pop.csv

Gijs Dekkers

unread,
Dec 16, 2020, 6:10:08 AM12/16/20
to liam2-users
apologies, I made a mistake in copy/paste'in; the issue is when I read
>>> (load('../../output/temp/al_f_active_pop.csv', type = float)[:])
 - reading C:\usr\midas\output\temp\al_f_active_pop.csv

agegroup_work |       |        |        |        |        |        |        |        |        |       |      |     
           15 | 37.17 | 196.25 | 295.65 | 312.12 | 305.00 | 327.52 | 332.00 | 300.48 | 226.72 | 96.20 | 4.11 | 1.97

which is incorrect

Gijs

(thanks, Raph)

Op woensdag 16 december 2020 om 12:04:51 UTC+1 schreef Gijs Dekkers:

Gijs Dekkers

unread,
Dec 16, 2020, 7:13:22 AM12/16/20
to liam2-users
Dear all,

Never mind; thanks to Raph the issue  is resolved
I did ...

(load('../../output/temp/al_f_active_pop.csv', type = float)[:])

but what I *should* have done was...

(load('../../output/temp/al_f_active_pop.csv', type = float))

so not including the ' [:]'.

And that resolves the issue. I owe Raph a beer. Thanks!

Gijs

Op woensdag 16 december 2020 om 12:10:08 UTC+1 schreef Gijs Dekkers:
Reply all
Reply to author
Forward
0 new messages