简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM