Pandas: parse .csv string type number with dot as thousand separator to int instead of float

Question:

It’s a .csv with items and prices. The latter already come rounded (without decimal) but if the price is more than 999, then I have to deal with the thousand separator.

item, price
foo, 12
bar,678
baz, 1.200


`df.dtype` returns:
item         object
price       float64

If I try to convert to int it truncates the number. So instead of 1.200 (one thousand two hundred) I get 1 (one)

Ps: I winded up deleting the dots with regex, but there has to be a proper way to handle this situation.

Asked By: ranemirusG

||

Answers:

As mentioned by @BigBen there’s a pd.read_csv parameter called thousands used to indicate the thousand separator. There’s also a decimal parameter which may be useful too.

Answered By: ranemirusG
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.