subtraction

Python error in basic subtraction? [duplicate]

爱⌒轻易说出口 提交于 2021-01-17 06:56:51
问题 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:30
问题 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

r multiple column subtraction

佐手、 提交于 2020-06-27 23:49:48
问题 The reduced version of my dataset is as shown below. Z_dog1_mu1 Z_dog2_mu1 Z_dog3_mu1 Z_cat1_mu1 Z_cat2_mu1 Z_cat3_mu1 0.0000 0.0000 0.0001 0.0005 0.0043 0.0045 0.0039 -0.0016 -0.0102 -0.0009 0.0421 -0.0139 -0.0380 -0.0733 0.0196 0.0261 0.0628 0.0463 -0.1036 0.0784 -0.0529 0.1053 -0.0511 -0.0138 I am trying to substract the dog* columns from the cat* columns like this df$diff1 <- df$Z_dog1_mu1 - df$Z_cat1_mu1 df$diff2 <- df$Z_dog2_mu1 - df$Z_cat2_mu1 df$diff3 <- df$Z_dog3_mu1 - df$Z_cat3_mu1

pandas: subtracting current date from the date in a pandas table

限于喜欢 提交于 2020-05-23 17:47:24
问题 I am attempting to calculate the difference in days between todays and a pandas data consisting of historical data. Below is the intended code: df['diff'] = pd.to_datetime( df['date']) - pd.datetime.now().date() However, it produces the following error: TypeError: unsupported operand type(s) for -: 'DatetimeIndex' and 'datetime.date' The date column in the pandas table looks like this: 0 2018-12-18 1 2018-12-18 2 2018-12-18 3 2018-12-18 4 2018-12-18 How do I fix this error. Thanks in advance.

NaNs when subtracting dataframes pandas

独自空忆成欢 提交于 2020-05-12 11:27:33
问题 I have two dataframes with only somewhat overlapping indices and columns. old = pd.DataFrame(index = ['A', 'B', 'C'], columns = ['k', 'l', 'm'], data = abs(np.floor(np.random.rand(3, 3)*10))) new = pd.DataFrame(index = ['A', 'B', 'C', 'D'], columns = ['k', 'l', 'm', 'n'], data = abs(np.floor(np.random.rand(4, 4)*10))) I want to calculate the difference between them and tried delta = new - old This gives lots of NaNs where indices and columns do not match. I would like to treat the abscence of

NaNs when subtracting dataframes pandas

↘锁芯ラ 提交于 2020-05-12 11:25:07
问题 I have two dataframes with only somewhat overlapping indices and columns. old = pd.DataFrame(index = ['A', 'B', 'C'], columns = ['k', 'l', 'm'], data = abs(np.floor(np.random.rand(3, 3)*10))) new = pd.DataFrame(index = ['A', 'B', 'C', 'D'], columns = ['k', 'l', 'm', 'n'], data = abs(np.floor(np.random.rand(4, 4)*10))) I want to calculate the difference between them and tried delta = new - old This gives lots of NaNs where indices and columns do not match. I would like to treat the abscence of

R subtracting 1 month from today's date gives NA

会有一股神秘感。 提交于 2020-04-27 06:03:12
问题 I have a script in which I subset my data according to some set time periods and wanted to subset all the records that had occurred in the last month. However if I try to subtract one month from today's date it yields an NA: > today <- Sys.Date() > today [1] "2017-03-29" > today - months(1) [1] NA I do have lubridate loaded but I think this calculation is being performed with base R. If I subtract 2 or more months it works fine: > today - months(2) [1] "2017-01-29" > today - months(3) [1]

R subtracting 1 month from today's date gives NA

狂风中的少年 提交于 2020-04-27 06:02:05
问题 I have a script in which I subset my data according to some set time periods and wanted to subset all the records that had occurred in the last month. However if I try to subtract one month from today's date it yields an NA: > today <- Sys.Date() > today [1] "2017-03-29" > today - months(1) [1] NA I do have lubridate loaded but I think this calculation is being performed with base R. If I subtract 2 or more months it works fine: > today - months(2) [1] "2017-01-29" > today - months(3) [1]