Skip to content Skip to sidebar Skip to footer

How To Read The Custom Table In Pandas Which Has Number String Number Number?

I have been trying to read a custom table in pandas but am getting errors for a long time. Here is the outline of table: Number string number number there is only one white space

Solution 1:

You can specify a delimiter that is a space not preceded by a letter (?<![a-zA-Z])\s, or | a space that is followed by a number \s(?=\d).

sep = r'(?<![a-zA-Z])\s|\s(?=\d)'
df = pd.read_csv('station.tsv', engine='python', sep=sep, header=None)

      0                  1    2    3
0   794    Kissee Mills MO  140   73
1   824        Loma Mar CA   49  131
2   603      Sandy Hook CT   72  148
3   478          Tipton IN   34   98
4   619       Arlington CO   75   93
5   711          Turner AR   50  101
6   839         Slidell LA   85  152
7   411         Negreet LA   99  105
8   588         Glencoe KY   46  136
9   665         Chelsea IA   99   60
10  957  South El Monte CA   74   80

df.dtypes
#0     int64
#1    object
#2     int64
#3     int64

Post a Comment for "How To Read The Custom Table In Pandas Which Has Number String Number Number?"