subtraction

subtracting two columns from pandas dataframe and store the result in third column [closed]

我的梦境 提交于 2021-02-19 05:42:54
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question I have a DataFrame, df , with 3 columns and I want to perform subtraction as follows: df['available'] = df['recommended'] - df['manual input'] But I am getting an error stating: unsupported operand type(s) for -: 'int' and 'str' I have also tried doing df['available'] = df[

SQL Subtract Column Values Based on Second Column Value with Group By Statement

Deadly 提交于 2021-02-16 20:01:25
问题 I have an SQL statement that looks so: select FY_CD, PD_NO, INPUT, SUM(HOURS) from LABOR_TABLE group by PD_NO, INPUT; Returning this: FY_CD|PD_NO| INPUT | HOURS 2008 1 Actuals 61000 2008 1 Baseline 59000 2008 2 Actuals 54000 2008 2 Baseline 59000 2008 3 Actuals 60000 2008 3 Baseline 70000 I'm trying to figure out how to subtract the Actual values from the Baseline values for each period, returning the following: FY_CD|PD_NO| INPUT | HOURS 2008 1 Variance 2000 2008 2 Variance -5000 2008 3

Find difference between 2 columns with Nulls using pandas

﹥>﹥吖頭↗ 提交于 2021-02-10 05:27:51
问题 I want to find the difference between 2 columns of type int in a pandas DataFrame. I am using python 2.7. The columns are as below - >>> df INVOICED_QUANTITY QUANTITY_SHIPPED 0 15 NaN 1 20 NaN 2 7 NaN 3 7 NaN 4 7 NaN Now, I want to subtract QUANTITY_SHIPPED from INVOICED_QUANTITY & I do the below- >>> df['Diff'] = df['QUANTITY_INVOICED'] - df['SHIPPED_QUANTITY'] >>> df QUANTITY_INVOICED SHIPPED_QUANTITY Diff 0 15 NaN NaN 1 20 NaN NaN 2 7 NaN NaN 3 7 NaN NaN 4 7 NaN NaN How do I take care of

Subtract consecutive columns in a Pandas or Pyspark Dataframe

北战南征 提交于 2021-02-04 15:51:45
问题 I would like to perform the following operation in a pandas or pyspark dataframe but i still havent found a solution. I want to subtract the values from consecutive columns in a dataframe. The operation I am describing can be seen in the image below. Bear in mind that the output dataframe wont have any values on first column as the first column in the input table cannot be subtracted by its previous one as it doesn't exist. 回答1: diff has an axis param so you can just do this in one step: In

Subtract consecutive columns in a Pandas or Pyspark Dataframe

北城余情 提交于 2021-02-04 15:51:24
问题 I would like to perform the following operation in a pandas or pyspark dataframe but i still havent found a solution. I want to subtract the values from consecutive columns in a dataframe. The operation I am describing can be seen in the image below. Bear in mind that the output dataframe wont have any values on first column as the first column in the input table cannot be subtracted by its previous one as it doesn't exist. 回答1: diff has an axis param so you can just do this in one step: In

How to select duplicate rows with pandas?

空扰寡人 提交于 2021-02-04 10:59:23
问题 I have a dataframe like this: import pandas as pd dic = {'A':[100,200,250,300], 'B':['ci','ci','po','pa'], 'C':['s','t','p','w']} df = pd.DataFrame(dic) My goal is to separate the row in 2 dataframes: df1 = contains all the rows that do not repeat values along column B (unque rows). df2 = containts only the rows who repeat themeselves. The result should look like this: df1 = A B C df2 = A B C 0 250 po p 0 100 ci s 1 300 pa w 1 250 ci t Note: the dataframes could be in general very big and

Subtraction of pandas dataframes

烂漫一生 提交于 2021-01-28 07:22:34
问题 I am trying to substract two pandas dataframes from each other, but get only NaN results: Dataframe 1: alpha beta 0 1 4 1 2 5 2 3 6 Dataframe 2: gamma 0 7 1 8 2 9 Dataframe operation: df3=df1-df2 Result: alpha beta gamma 0 NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN However, if I convert everything to numpy matrices, it works: Matrix operation: matrix3=df1.as_matrix(['alpha','beta'])-df2.as_matrix(['gamma']) Result: [[-6 -3] [-6 -3] [-6 -3]] How can I make this work with pandas? 回答1: Either of

Python error in basic subtraction? [duplicate]

ⅰ亾dé卋堺 提交于 2021-01-17 06:59:49
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Python rounding error with float numbers python maths is wrong I can't get Python to correctly do the subtraction 1 - 0.8 and assign it. It keeps coming up with the incorrect answer, 0.19999999999999996. I explored a bit: sq = {} sub = {} for i in range(1000): sq[str(i/1000.)+'**2']=((i/1000.)**2) sub['1-'+str(i/1000.)]=(1.0-(i/1000.)) and discovered that this error happens with a somewhat random group of the

Python error in basic subtraction? [duplicate]

主宰稳场 提交于 2021-01-17 06:59:22
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Python rounding error with float numbers python maths is wrong I can't get Python to correctly do the subtraction 1 - 0.8 and assign it. It keeps coming up with the incorrect answer, 0.19999999999999996. I explored a bit: sq = {} sub = {} for i in range(1000): sq[str(i/1000.)+'**2']=((i/1000.)**2) sub['1-'+str(i/1000.)]=(1.0-(i/1000.)) and discovered that this error happens with a somewhat random group of the

Python error in basic subtraction? [duplicate]

你离开我真会死。 提交于 2021-01-17 06:56:56
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Python rounding error with float numbers python maths is wrong I can't get Python to correctly do the subtraction 1 - 0.8 and assign it. It keeps coming up with the incorrect answer, 0.19999999999999996. I explored a bit: sq = {} sub = {} for i in range(1000): sq[str(i/1000.)+'**2']=((i/1000.)**2) sub['1-'+str(i/1000.)]=(1.0-(i/1000.)) and discovered that this error happens with a somewhat random group of the