Liubey135
Liubey135

Reputation: 19

Appending a column in a csv file

I was having some trouble with csv files. I would like to add a new column, that being a multiplication of the previous one. For instance ['price', 'pricex2'] [[2,4],[6,12]] and so on, how could I do that?

I also happen to have € signs at the end of every number in the price column, but I think I can tackle that by taking the float for the 4 first characters right? For example price = 2,45€ numericalPrice = float(price[0:3]).

I would rather not use pandas as it gives me trouble when installing.

Upvotes: 0

Views: 39

Answers (1)

JeffUK
JeffUK

Reputation: 4231

I'll answer the second part of the question, because your suggestion is dangerous. If the price is not exactly 4 characters long it fails. You should do:

price = "2,45€"
numericalprice = float(price[:-1])
print(numericalprice)

Upvotes: 1

Related Questions