-1

enter image description here

I want to perform a few arithmetic operations on few columns and after operations are get performed again I need to put down result in CSV. After adding result into CSV, resultant answer needs to compare with total_sales_price and accordingly output will shown as true or false.

Please refer my code suggest me what should I need to do.

data = pd.read_csv('pandastest.csv')
df = pd.DataFrame(data) 
df.head()
#Result = np.where(data.sales_price/(1-(data.margin_pct/100)))
df['Result'] = (df['sales_price']/(1-(df['margin_pct']/100)))
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • to put down the result into csv again use df.to_csv(). you can do the comparison of two columns also the same way or you can write a lambda or a function and use .apply() method. example : df['comp'] = df['Result']==df['total_sale_price'] – cerofrais Oct 09 '19 at 05:25
  • Please [provide a reproducible copy of the DataFrame with `to_clipboard`](https://stackoverflow.com/questions/52413246/provide-a-reproducible-copy-of-the-dataframe-with-to-clipboard/52413247#52413247) – Trenton McKinney Oct 09 '19 at 05:44
  • [Stack Overflow Discourages Screenshots](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). It is likely, the question will be downvoted, for containing unnecessary screenshots. By using screenshots, you are discouraging anyone from assisting you. No one wants to retype your stuff, from a screenshot, and screenshots are often, not readable. – Trenton McKinney Oct 09 '19 at 05:44

1 Answers1

0

You can compare the fields and store the result of comparison in your result column and then push it to a csv.

df = pd.DataFrame(data) 
df.head()
df['Result'] = df['total_sales_price'] == (df['sales_price']/(1-(df['margin_pct']/100)))
print(df['Result'])
df.to_csv("result.csv")
Arif Eqbal
  • 3,068
  • 1
  • 18
  • 10