I have a CSV file like this:
Time Latitude Longitude
2021-09-12 23:13 44.63 -63.56
2021-09-14 23:13 43.78 -62
2021-09-16 23:14 44.83 -54.6
2021-09-12 23:13
is under Time
column.
I would like to open it using pandas. But there is a problem with the first column. It contains a space. If I open it using:
import pandas as pd
points = pd.read_csv("test.csv", delim_whitespace=True)
I get
Time | Latitude | Longitude | |
---|---|---|---|
2021-09-12 | 23:13 | 44.630 | -63.560 |
2021-09-14 | 23:13 | 43.780 | -62.000 |
2021-09-16 | 23:14 | 44.830 | -54.600 |
But I would like to skip the space in the first column in CSV (2021-09-12 23:13
should be under Time
column) like:
Time | Latitude | Longitude | |
---|---|---|---|
0 | 2021-09-12 23:13 | 44.630 | -63.560 |
1 | 2021-09-14 23:13 | 43.780 | -62.000 |
2 | 2021-09-16 23:14 | 44.830 | -54.600 |
How can I ignore the first space when using pd.read_csv
?
Please do not stick to this csv file. This is a general question to skip (not to consider as a delimiter) the first space(s) in the first column. Because everyone knows that the first space is part of the time value, not a delimiter.
delim_whitespace=True
, you could usesep=\t
. Spaces in column values then wouldn't matter.