Python read text file columnwise
Cameron Simpson
cs at cskk.id.au
Fri Jan 11 20:54:30 EST 2019
On 11Jan2019 12:43, shibashibani at gmail.com <shibashibani at gmail.com> wrote:
>I'm very new in python. I have a file in the format:
>
>2018-05-31 16:00:00 28.90 81.77 4.3
>2018-05-31 20:32:00 28.17 84.89 4.1
>2018-06-20 04:09:00 27.36 88.01 4.8
>2018-06-20 04:15:00 27.31 87.09 4.7
>2018-06-28 04.07:00 27.87 84.91 5.0
>2018-06-29 00.42:00 32.20 104.61 4.8
It is unclear what delimits the columns, but it looks like whitespace:
tabs and/or spaces.
You could read the file a line at a time and call .split() on each line
to get the nonwhitespace fields, which would seem to correspond to the
columns above.
That gets you an list of strings; then you could convert them for
processing as required.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list