GitHub profile

Overview

Taking Logarithms

Identifying Negatives

An inspection on our dataset identifies 6 rows that contain negatives.


import subprocess  
%run ./dataframes/step3_identify_negatives.py  
df = identify_negs()  
subprocess.run(['wl-copy'], input=df.to_html(index=False).encode())  
Date 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14 14.5 15 15.5 16 16.5 17 17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 22.5 23 23.5 24 24.5 25 25.5 26 26.5 27 27.5 28 28.5 29 29.5 30 30.5 31 31.5 32 32.5 33 33.5 34 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 39.5 40
2020-05-31 -0.04 -0.02 -0.01 0.01 0.03 0.05 0.07 0.10 0.13 0.16 0.18 0.21 0.24 0.27 0.30 0.33 0.36 0.38 0.41 0.43 0.45 0.47 0.49 0.51 0.53 0.54 0.56 0.57 0.58 0.60 0.60 0.61 0.62 0.63 0.63 0.64 0.64 0.64 0.65 0.65 0.65 0.65 0.64 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.59 0.58 0.58 0.57 0.56 0.55 0.55 0.54 0.53 0.52 0.52 0.51 0.50 0.49 0.49 0.48 0.48 0.47 0.47
2020-06-30 -0.06 -0.05 -0.03 -0.01 0.02 0.04 0.07 0.10 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.44 0.47 0.49 0.51 0.54 0.56 0.58 0.59 0.61 0.62 0.64 0.65 0.66 0.67 0.68 0.68 0.69 0.69 0.70 0.70 0.70 0.70 0.70 0.70 0.70 0.69 0.69 0.69 0.68 0.68 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.56 0.56
2020-07-31 -0.13 -0.11 -0.10 -0.08 -0.05 -0.03 0.00 0.03 0.06 0.09 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.43 0.46 0.48 0.51 0.53 0.55 0.57 0.58 0.60 0.61 0.62 0.64 0.65 0.65 0.66 0.67 0.67 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.67 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.57 0.56
2020-08-31 -0.00 0.03 0.06 0.09 0.12 0.16 0.20 0.24 0.28 0.31 0.35 0.39 0.43 0.47 0.50 0.54 0.57 0.60 0.64 0.67 0.69 0.72 0.75 0.77 0.79 0.81 0.83 0.85 0.87 0.88 0.89 0.91 0.92 0.93 0.94 0.94 0.95 0.95 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.95 0.95 0.95 0.94 0.94 0.94 0.93 0.93 0.92 0.92 0.91 0.91 0.90 0.90 0.89 0.89 0.89 0.88 0.88 0.87 0.87 0.86 0.86 0.86
2020-09-30 -0.06 -0.04 -0.01 0.02 0.05 0.08 0.11 0.15 0.18 0.22 0.26 0.29 0.33 0.36 0.40 0.43 0.46 0.50 0.53 0.55 0.58 0.61 0.63 0.65 0.67 0.69 0.71 0.73 0.74 0.76 0.77 0.78 0.79 0.80 0.81 0.81 0.82 0.82 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.82 0.82 0.82 0.81 0.81 0.81 0.80 0.80 0.79 0.79 0.78 0.78 0.77 0.77 0.77 0.76 0.76 0.75 0.75 0.74 0.74 0.73 0.73 0.73 0.72 0.72
2020-10-31 -0.02 -0.00 0.02 0.05 0.08 0.12 0.15 0.19 0.22 0.26 0.30 0.33 0.37 0.41 0.44 0.48 0.51 0.54 0.57 0.60 0.63 0.65 0.68 0.70 0.72 0.74 0.76 0.78 0.79 0.81 0.82 0.83 0.84 0.85 0.86 0.86 0.87 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.87 0.87 0.86 0.86 0.86 0.85 0.85 0.84 0.84 0.83 0.83 0.82 0.82 0.81 0.80 0.80 0.79 0.79 0.79 0.78 0.78 0.77 0.77
2020-12-31 -0.06 -0.04 -0.02 0.01 0.04 0.07 0.10 0.13 0.16 0.20 0.23 0.26 0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.53 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.71 0.72 0.74 0.75 0.76 0.77 0.77 0.78 0.79 0.79 0.79 0.80 0.80 0.80 0.80 0.80 0.79 0.79 0.79 0.79 0.78 0.78 0.77 0.77 0.76 0.76 0.75 0.74 0.74 0.73 0.73 0.72 0.72 0.71 0.70 0.70 0.69 0.69 0.68 0.68 0.67 0.67

We can see that those rows don't have negatives for columns terms 8 and above.


import subprocess  
%run ./dataframes/step3_identify_negatives.py  
df = identify_negs()  
df = df.drop(columns=[8.5, 9,    9.5,     10,   10.5,     11,   11.5,     12,   12.5,     13, 13.5,     14,   14.5,     15,   15.5,     16,   16.5,     17,   17.5, 18,   18.5,     19,   19.5,     20,   20.5,     21,   21.5,     22, 22.5,     23,   23.5,     24,   24.5,     25,   25.5,     26,   26.5, 27,   27.5,     28,   28.5,     29,   29.5,     30,   30.5,     31, 31.5,     32,   32.5,     33,   33.5,     34,   34.5,     35,   35.5, 36,   36.5,     37,   37.5,     38,   38.5,     39,   39.5,     40])
subprocess.run(['wl-copy'], input=df.to_html(index=False).encode())  
Date 5 5.5 6 6.5 7 7.5 8
2020-05-31 -0.04 -0.02 -0.01 0.01 0.03 0.05 0.07
2020-06-30 -0.06 -0.05 -0.03 -0.01 0.02 0.04 0.07
2020-07-31 -0.13 -0.11 -0.10 -0.08 -0.05 -0.03 0.00
2020-08-31 -0.00 0.03 0.06 0.09 0.12 0.16 0.20
2020-09-30 -0.06 -0.04 -0.01 0.02 0.05 0.08 0.11
2020-10-31 -0.02 -0.00 0.02 0.05 0.08 0.12 0.15
2020-12-31 -0.06 -0.04 -0.02 0.01 0.04 0.07 0.10

Replacing negatives

We replace negatives with NaN


import subprocess  
%run ./dataframes/step3_replace_negatives_with_nan.py  
df = replace_negs()  
subprocess.run(['wl-copy'], input=df.to_html(index=False).encode())  
Date 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14 14.5 15 15.5 16 16.5 17 17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 22.5 23 23.5 24 24.5 25 25.5 26 26.5 27 27.5 28 28.5 29 29.5 30 30.5 31 31.5 32 32.5 33 33.5 34 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 39.5 40
2020-05-31 NaN NaN NaN 0.01 0.03 0.05 0.07 0.10 0.13 0.16 0.18 0.21 0.24 0.27 0.30 0.33 0.36 0.38 0.41 0.43 0.45 0.47 0.49 0.51 0.53 0.54 0.56 0.57 0.58 0.60 0.60 0.61 0.62 0.63 0.63 0.64 0.64 0.64 0.65 0.65 0.65 0.65 0.64 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.59 0.58 0.58 0.57 0.56 0.55 0.55 0.54 0.53 0.52 0.52 0.51 0.50 0.49 0.49 0.48 0.48 0.47 0.47
2020-06-30 NaN NaN NaN NaN 0.02 0.04 0.07 0.10 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.44 0.47 0.49 0.51 0.54 0.56 0.58 0.59 0.61 0.62 0.64 0.65 0.66 0.67 0.68 0.68 0.69 0.69 0.70 0.70 0.70 0.70 0.70 0.70 0.70 0.69 0.69 0.69 0.68 0.68 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.56 0.56
2020-07-31 NaN NaN NaN NaN NaN NaN NaN 0.03 0.06 0.09 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.43 0.46 0.48 0.51 0.53 0.55 0.57 0.58 0.60 0.61 0.62 0.64 0.65 0.65 0.66 0.67 0.67 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.67 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.57 0.56
2020-08-31 NaN 0.03 0.06 0.09 0.12 0.16 0.20 0.24 0.28 0.31 0.35 0.39 0.43 0.47 0.50 0.54 0.57 0.60 0.64 0.67 0.69 0.72 0.75 0.77 0.79 0.81 0.83 0.85 0.87 0.88 0.89 0.91 0.92 0.93 0.94 0.94 0.95 0.95 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.96 0.95 0.95 0.95 0.94 0.94 0.94 0.93 0.93 0.92 0.92 0.91 0.91 0.90 0.90 0.89 0.89 0.89 0.88 0.88 0.87 0.87 0.86 0.86 0.86
2020-09-30 NaN NaN NaN 0.02 0.05 0.08 0.11 0.15 0.18 0.22 0.26 0.29 0.33 0.36 0.40 0.43 0.46 0.50 0.53 0.55 0.58 0.61 0.63 0.65 0.67 0.69 0.71 0.73 0.74 0.76 0.77 0.78 0.79 0.80 0.81 0.81 0.82 0.82 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.82 0.82 0.82 0.81 0.81 0.81 0.80 0.80 0.79 0.79 0.78 0.78 0.77 0.77 0.77 0.76 0.76 0.75 0.75 0.74 0.74 0.73 0.73 0.73 0.72 0.72
2020-10-31 NaN NaN 0.02 0.05 0.08 0.12 0.15 0.19 0.22 0.26 0.30 0.33 0.37 0.41 0.44 0.48 0.51 0.54 0.57 0.60 0.63 0.65 0.68 0.70 0.72 0.74 0.76 0.78 0.79 0.81 0.82 0.83 0.84 0.85 0.86 0.86 0.87 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.87 0.87 0.86 0.86 0.86 0.85 0.85 0.84 0.84 0.83 0.83 0.82 0.82 0.81 0.80 0.80 0.79 0.79 0.79 0.78 0.78 0.77 0.77
2020-12-31 NaN NaN NaN 0.01 0.04 0.07 0.10 0.13 0.16 0.20 0.23 0.26 0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.53 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.71 0.72 0.74 0.75 0.76 0.77 0.77 0.78 0.79 0.79 0.79 0.80 0.80 0.80 0.80 0.80 0.79 0.79 0.79 0.79 0.78 0.78 0.77 0.77 0.76 0.76 0.75 0.74 0.74 0.73 0.73 0.72 0.72 0.71 0.70 0.70 0.69 0.69 0.68 0.68 0.67 0.67

Interpolating to replace the NaNs


import subprocess  
%run ./dataframes/step3_interpolating_over_nan.py  
df = interpolating_nans()  
df = df.loc[[604, 605, 606, 608, 609, 611]]
subprocess.run(['wl-copy'], input=df.to_html(index=False).encode())  

Date 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14 14.5 15 15.5 16 16.5 17 17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 22.5 23 23.5 24 24.5 25 25.5 26 26.5 27 27.5 28 28.5 29 29.5 30 30.5 31 31.5 32 32.5 33 33.5 34 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 39.5 40
2020-05-31 0.057143 0.06 0.075 0.010000 0.03 0.05 0.070 0.10 0.13 0.16 0.18 0.21 0.24 0.27 0.30 0.33 0.36 0.38 0.41 0.43 0.45 0.47 0.49 0.51 0.53 0.54 0.56 0.57 0.58 0.60 0.60 0.61 0.62 0.63 0.63 0.64 0.64 0.64 0.65 0.65 0.65 0.65 0.64 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.59 0.58 0.58 0.57 0.56 0.55 0.55 0.54 0.53 0.52 0.52 0.51 0.50 0.49 0.49 0.48 0.48 0.47 0.47
2020-06-30 0.054286 0.05 0.070 0.036667 0.02 0.04 0.070 0.10 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.44 0.47 0.49 0.51 0.54 0.56 0.58 0.59 0.61 0.62 0.64 0.65 0.66 0.67 0.68 0.68 0.69 0.69 0.70 0.70 0.70 0.70 0.70 0.70 0.70 0.69 0.69 0.69 0.68 0.68 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.56 0.56
2020-07-31 0.051429 0.04 0.065 0.063333 0.07 0.10 0.135 0.03 0.06 0.09 0.13 0.16 0.19 0.22 0.26 0.29 0.32 0.35 0.38 0.41 0.43 0.46 0.48 0.51 0.53 0.55 0.57 0.58 0.60 0.61 0.62 0.64 0.65 0.65 0.66 0.67 0.67 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.68 0.67 0.67 0.67 0.66 0.66 0.65 0.65 0.64 0.64 0.63 0.63 0.62 0.62 0.61 0.61 0.60 0.60 0.59 0.59 0.58 0.58 0.57 0.57 0.57 0.56
2020-09-30 0.045714 0.04 0.040 0.020000 0.05 0.08 0.110 0.15 0.18 0.22 0.26 0.29 0.33 0.36 0.40 0.43 0.46 0.50 0.53 0.55 0.58 0.61 0.63 0.65 0.67 0.69 0.71 0.73 0.74 0.76 0.77 0.78 0.79 0.80 0.81 0.81 0.82 0.82 0.83 0.83 0.83 0.83 0.83 0.83 0.83 0.82 0.82 0.82 0.81 0.81 0.81 0.80 0.80 0.79 0.79 0.78 0.78 0.77 0.77 0.77 0.76 0.76 0.75 0.75 0.74 0.74 0.73 0.73 0.73 0.72 0.72
2020-10-31 0.042857 0.05 0.020 0.050000 0.08 0.12 0.150 0.19 0.22 0.26 0.30 0.33 0.37 0.41 0.44 0.48 0.51 0.54 0.57 0.60 0.63 0.65 0.68 0.70 0.72 0.74 0.76 0.78 0.79 0.81 0.82 0.83 0.84 0.85 0.86 0.86 0.87 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.87 0.87 0.86 0.86 0.86 0.85 0.85 0.84 0.84 0.83 0.83 0.82 0.82 0.81 0.80 0.80 0.79 0.79 0.79 0.78 0.78 0.77 0.77
2020-12-31 0.025000 0.05 0.085 0.010000 0.04 0.07 0.100 0.13 0.16 0.20 0.23 0.26 0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.53 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.71 0.72 0.74 0.75 0.76 0.77 0.77 0.78 0.79 0.79 0.79 0.80 0.80 0.80 0.80 0.80 0.79 0.79 0.79 0.79 0.78 0.78 0.77 0.77 0.76 0.76 0.75 0.74 0.74 0.73 0.73 0.72 0.72 0.71 0.70 0.70 0.69 0.69 0.68 0.68 0.67 0.67

Checks on the interpolation

It is best to add in a check to ensure that the process has been performed correctly...

to do a sense check we obtain a count of the negative values we had


import subprocess  
%run ./dataframes/step3_count_nans.py  
df = count_nans()  

and we consider the sum of the data before and after the interpolation


import subprocess  
%run ./dataframes/step3_sum_before_interpolation.py
df = sum_before_interpolation()  

before the sum is ... 16195.080000000002


import subprocess  
%run ./dataframes/step3_sum_after_interpolation.py
df = sum_after_interpolation()  

after the sum is ... 16197.025000000001

Taking Logarithms

we could improve couple of tables below as losing 1 row with the filter


import subprocess  
%run ./dataframes/step3_taking_logs.py  
df = taking_logs()  
df = df.loc[[604, 605, 606, 608, 609, 611]]
subprocess.run(['wl-copy'], input=df.to_html(index=False).encode())  
Date 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14 14.5 15 15.5 16 16.5 17 17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 22.5 23 23.5 24 24.5 25 25.5 26 26.5 27 27.5 28 28.5 29 29.5 30 30.5 31 31.5 32 32.5 33 33.5 34 34.5 35 35.5 36 36.5 37 37.5 38 38.5 39 39.5 40
2020-05-31 -2.862201 -2.813411 -2.590267 -4.605170 -3.506558 -2.995732 -2.659260 -2.302585 -2.040221 -1.832581 -1.714798 -1.560648 -1.427116 -1.309333 -1.203973 -1.108663 -1.021651 -0.967584 -0.891598 -0.843970 -0.798508 -0.755023 -0.713350 -0.673345 -0.634878 -0.616186 -0.579818 -0.562119 -0.544727 -0.510826 -0.510826 -0.494296 -0.478036 -0.462035 -0.462035 -0.446287 -0.446287 -0.446287 -0.430783 -0.430783 -0.430783 -0.430783 -0.446287 -0.446287 -0.446287 -0.462035 -0.462035 -0.478036 -0.478036 -0.494296 -0.494296 -0.510826 -0.527633 -0.544727 -0.544727 -0.562119 -0.579818 -0.597837 -0.597837 -0.616186 -0.634878 -0.653926 -0.653926 -0.673345 -0.693147 -0.713350 -0.713350 -0.733969 -0.733969 -0.755023 -0.755023
2020-06-30 -2.913494 -2.995732 -2.659260 -3.305887 -3.912023 -3.218876 -2.659260 -2.302585 -2.040221 -1.832581 -1.660731 -1.514128 -1.347074 -1.237874 -1.139434 -1.049822 -0.967584 -0.891598 -0.820981 -0.755023 -0.713350 -0.673345 -0.616186 -0.579818 -0.544727 -0.527633 -0.494296 -0.478036 -0.446287 -0.430783 -0.415515 -0.400478 -0.385662 -0.385662 -0.371064 -0.371064 -0.356675 -0.356675 -0.356675 -0.356675 -0.356675 -0.356675 -0.356675 -0.371064 -0.371064 -0.371064 -0.385662 -0.385662 -0.400478 -0.400478 -0.415515 -0.415515 -0.430783 -0.430783 -0.446287 -0.446287 -0.462035 -0.478036 -0.478036 -0.494296 -0.494296 -0.510826 -0.510826 -0.527633 -0.527633 -0.544727 -0.544727 -0.562119 -0.562119 -0.579818 -0.579818
2020-07-31 -2.967561 -3.218876 -2.733368 -2.759343 -2.659260 -2.302585 -2.002481 -3.506558 -2.813411 -2.407946 -2.040221 -1.832581 -1.660731 -1.514128 -1.347074 -1.237874 -1.139434 -1.049822 -0.967584 -0.891598 -0.843970 -0.776529 -0.733969 -0.673345 -0.634878 -0.597837 -0.562119 -0.544727 -0.510826 -0.494296 -0.478036 -0.446287 -0.430783 -0.430783 -0.415515 -0.400478 -0.400478 -0.385662 -0.385662 -0.385662 -0.385662 -0.385662 -0.385662 -0.385662 -0.385662 -0.385662 -0.400478 -0.400478 -0.400478 -0.415515 -0.415515 -0.430783 -0.430783 -0.446287 -0.446287 -0.462035 -0.462035 -0.478036 -0.478036 -0.494296 -0.494296 -0.510826 -0.510826 -0.527633 -0.527633 -0.544727 -0.544727 -0.562119 -0.562119 -0.562119 -0.579818
2020-09-30 -3.085344 -3.218876 -3.218876 -3.912023 -2.995732 -2.525729 -2.207275 -1.897120 -1.714798 -1.514128 -1.347074 -1.237874 -1.108663 -1.021651 -0.916291 -0.843970 -0.776529 -0.693147 -0.634878 -0.597837 -0.544727 -0.494296 -0.462035 -0.430783 -0.400478 -0.371064 -0.342490 -0.314711 -0.301105 -0.274437 -0.261365 -0.248461 -0.235722 -0.223144 -0.210721 -0.210721 -0.198451 -0.198451 -0.186330 -0.186330 -0.186330 -0.186330 -0.186330 -0.186330 -0.186330 -0.198451 -0.198451 -0.198451 -0.210721 -0.210721 -0.210721 -0.223144 -0.223144 -0.235722 -0.235722 -0.248461 -0.248461 -0.261365 -0.261365 -0.261365 -0.274437 -0.274437 -0.287682 -0.287682 -0.301105 -0.301105 -0.314711 -0.314711 -0.314711 -0.328504 -0.328504
2020-10-31 -3.149883 -2.995732 -3.912023 -2.995732 -2.525729 -2.120264 -1.897120 -1.660731 -1.514128 -1.347074 -1.203973 -1.108663 -0.994252 -0.891598 -0.820981 -0.733969 -0.673345 -0.616186 -0.562119 -0.510826 -0.462035 -0.430783 -0.385662 -0.356675 -0.328504 -0.301105 -0.274437 -0.248461 -0.235722 -0.210721 -0.198451 -0.186330 -0.174353 -0.162519 -0.150823 -0.150823 -0.139262 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.127833 -0.139262 -0.139262 -0.150823 -0.150823 -0.150823 -0.162519 -0.162519 -0.174353 -0.174353 -0.186330 -0.186330 -0.198451 -0.198451 -0.210721 -0.223144 -0.223144 -0.235722 -0.235722 -0.235722 -0.248461 -0.248461 -0.261365 -0.261365
2020-12-31 -3.688879 -2.995732 -2.465104 -4.605170 -3.218876 -2.659260 -2.302585 -2.040221 -1.832581 -1.609438 -1.469676 -1.347074 -1.203973 -1.108663 -1.021651 -0.941609 -0.867501 -0.798508 -0.733969 -0.673345 -0.634878 -0.579818 -0.544727 -0.510826 -0.478036 -0.446287 -0.415515 -0.385662 -0.356675 -0.342490 -0.328504 -0.301105 -0.287682 -0.274437 -0.261365 -0.261365 -0.248461 -0.235722 -0.235722 -0.235722 -0.223144 -0.223144 -0.223144 -0.223144 -0.223144 -0.235722 -0.235722 -0.235722 -0.235722 -0.248461 -0.248461 -0.261365 -0.261365 -0.274437 -0.274437 -0.287682 -0.301105 -0.301105 -0.314711 -0.314711 -0.328504 -0.328504 -0.342490 -0.356675 -0.356675 -0.371064 -0.371064 -0.385662 -0.385662 -0.400478 -0.400478

Python

Functions

filename: step3_identify_negatives.py

from dataframes.step2_remove_upto_term_5 import *

def identify_negs():
    df = remove_upto_term5()

    # build the mask on numeric columns only
    mask = (df.iloc[:,1:] <= 0).any(axis=1)

    # apply mask to the FULL dataframe (keeps dates)
    identifying_negatives = df[mask]

    return identifying_negatives


We need to grab the dataset for step2 and identify negatives

filename: step3_replace_negatives_with_nan.py

from dataframes.step3_identify_negatives import *
import numpy as np

def replace_negs():
    df = identify_negs()
    numeric_cols = df.select_dtypes(include='number').columns #this gives you just a list of column names
    df[numeric_cols] = df[numeric_cols].where(df[numeric_cols] > 0, np.nan)
    return df
this is only for demonstration purposes. we need to apply this to the whole dataframe for the analysis

filename: step3_replace_negatives_with_nan_whole_dataframe.py

from dataframes.step3_identify_negatives import *
import numpy as np

def replace_negs():
    df = remove_upto_term5()
    numeric_cols = df.select_dtypes(include='number').columns #this gives you just a list of column names
    df[numeric_cols] = df[numeric_cols].where(df[numeric_cols] > 0, np.nan)
    return df
applied to the whole dataframe this time

filename: step3_interpolating_over_nan.py

from dataframes.step3_replace_negatives_with_nan_whole_dataframe import *
import numpy as np

def interpolating_nans():
    df = replace_negs()
    df[df.columns.difference(['Date'])] = df[df.columns.difference(['Date'])].interpolate()
    return df
we apply interpolate to the whole dataframe since we need values before and after the nans to make an interpolation

filename: step3_count_nans.py

from dataframes.step3_identify_negatives import *
import numpy as np

def count_nans():
    df = remove_upto_term5()
    numeric_cols = df.select_dtypes(include='number').columns #this gives you just a list of column names
    df[numeric_cols] = df[numeric_cols].where(df[numeric_cols] >= 0, np.nan)
    df = df.isna().sum().sum()
    print ( df )
    return df

count negative values