Sorry if I haven't explained things very well. I'm a complete novice please feel free to critic

I've searched every where but I havent found anything close to subtracting a percent. when its done on its own(x-.10=y) it works wonderfully. the only problem is Im trying to make 'x' stand for sample_.csv[0] or the numerical value from first column from my understanding.

import csv
import numpy as np 
import pandas as pd 

readdata = csv.reader(open("sample_.csv"))
x = input(sample_.csv[0])

y = input(x * .10)

print(x + y)

the column looks something like this "20,a," "25,b," "35,c," "45,d,"

2 Answers

0
Erik Gaasedelen On

I think you should only need pandas for this task. I'm guessing you want to apply this operation on one column:

import pandas as pd
df = pd.read_csv('sample_.csv') # assuming columns within csv header.
df['new_col'] = df['20,a'] * 1.1 # Faster than adding to a percentage x + 0.1x = 1.1*x
df.to_csv('new_sample.csv', index=False) # Default behavior is to write index, which I personally don't like.

BTW: input is a reserved command in python and asks for input from the user. I'm guessing you don't want this behavior but I could be wrong.

0
Syenix On
import pandas as pd
df = pd.read_csv("sample_.csv")
df['newcolumn'] = df['column'].apply(lambda x : x * .10) 

Please try this.