This is a follow up question from this question.
The data:
df1 = pd.DataFrame.from_dict({('group', ''): {0: 'A',
1: 'A',
2: 'A',
3: 'A',
4: 'A',
5: 'A',
6: 'A',
7: 'A',
8: 'B',
9: 'B',
10: 'B',
11: 'B',
12: 'B',
13: 'B',
14: 'B',
15: 'B',
16: 'C',
17: 'C',
18: 'C',
19: 'C',
20: 'C',
21: 'C',
22: 'C',
23: 'C',
24: 'D',
25: 'D',
26: 'D',
27: 'D',
28: 'D',
29: 'D',
30: 'D'},
('category', ''): {0: 'Apple',
1: 'Amazon',
2: 'Google',
3: 'Netflix',
4: 'Facebook',
5: 'Uber',
6: 'Tesla',
7: 'total',
8: 'Apple',
9: 'Amazon',
10: 'Google',
11: 'Netflix',
12: 'Facebook',
13: 'Uber',
14: 'Tesla',
15: 'total',
16: 'Apple',
17: 'Amazon',
18: 'Google',
19: 'Netflix',
20: 'Facebook',
21: 'Uber',
22: 'Tesla',
23: 'total',
24: 'Apple',
25: 'Amazon',
26: 'Google',
27: 'Netflix',
28: 'Uber',
29: 'Tesla',
30: 'total'},
(pd.Timestamp('2021-06-28 00:00:00'), 'total_orders'): {0: 88.0,
1: 66.0,
2: 191.0,
3: 558.0,
4: 12.0,
5: 4.0,
6: 56.0,
7: 975.0,
8: 90.0,
9: 26.0,
10: 49.0,
11: 250.0,
12: 7.0,
13: 2.0,
14: 44.0,
15: 468.0,
16: 36.0,
17: 52.0,
18: 94.0,
19: 750.0,
20: 10.0,
21: 0.0,
22: 52.0,
23: 994.0,
24: 16.0,
25: 22.0,
26: 5.0,
27: 57.0,
28: 3.0,
29: 33.0,
30: 136.0},
(pd.Timestamp('2021-06-28 00:00:00'), 'total_sales'): {0: 4603.209999999999,
1: 2485.059999999998,
2: 4919.39999999998,
3: 6097.77,
4: 31.22,
5: 155.71,
6: 3484.99,
7: 17237.35999999996,
8: 561.54,
9: 698.75,
10: 1290.13,
11: 4292.68000000001,
12: 947.65,
13: 329.0,
14: 2889.65,
15: 9989.4,
16: 330.8899999999994,
17: 2076.26,
18: 2982.270000000004,
19: 11978.62000000002,
20: 683.0,
21: 0.0,
22: 3812.16999999999,
23: 20963.21000000002,
24: 234.4900000000002,
25: 896.1,
26: 231.0,
27: 893.810000000001,
28: 129.0,
29: 1712.329999999998,
30: 4106.729999999996},
(pd.Timestamp('2021-07-05 00:00:00'), 'total_orders'): {0: 109.0,
1: 48.0,
2: 174.0,
3: 592.0,
4: 13.0,
5: 5.0,
6: 43.0,
7: 984.0,
8: 62.0,
9: 13.0,
10: 37.0,
11: 196.0,
12: 8.0,
13: 1.0,
14: 3.0,
15: 30.0,
16: 76.0,
17: 5.0,
18: 147.0,
19: 88.0,
20: 8.0,
21: 1.0,
22: 78.0,
23: 1248.0,
24: 1.0,
25: 18.0,
26: 23.0,
27: 83.0,
28: 0.0,
29: 29.0,
30: 154.0},
(pd.Timestamp('2021-07-05 00:00:00'), 'total_sales'): {0: 3453.02,
1: 17868.730000000003,
2: 44707.82999999999,
3: 61425.99,
4: 1261.0,
5: 1914.6000000000001,
6: 24146.09,
7: 154777.25999999998,
8: 6201.489999999999,
9: 5513.960000000001,
10: 9645.87,
11: 25086.785,
12: 663.0,
13: 448.61,
14: 26332.7,
15: 73892.415,
16: 556.749999999999,
17: 1746.859999999997,
18: 4103.219999999994,
19: 15571.52000000008,
20: 86.0,
21: 69.0,
22: 5882.759999999995,
23: 26476.11000000004,
24: 53.0,
25: 801.220000000001,
26: 684.56,
27: 1232.600000000002,
28: 0.0,
29: 15902.1,
30: 43943.48},
(pd.Timestamp('2021-07-12 00:00:00'), 'total_orders'): {0: 32.0,
1: 15.0,
2: 89.0,
3: 239.0,
4: 2.0,
5: 3.0,
6: 20.0,
7: 400.0,
8: 0.0,
9: 0.0,
10: 0.0,
11: 0.0,
12: 0.0,
13: 0.0,
14: 0.0,
15: 0.0,
16: 21.0,
17: 14.0,
18: 58.0,
19: 281.0,
20: 3.0,
21: 3.0,
22: 33.0,
23: 413.0,
24: 7.0,
25: 6.0,
26: 4.0,
27: 13.0,
28: 0.0,
29: 18.0,
30: 48.0},
(pd.Timestamp('2021-07-12 00:00:00'), 'total_sales'): {0: 2147.7000000000003,
1: 4767.3,
2: 2399.300000000003,
3: 3137.440000000002,
4: 178.0,
5: 866.61,
6: 10639.03,
7: 73235.38,
8: 0.0,
9: 0.0,
10: 0.0,
11: 0.0,
12: 0.0,
13: 0.0,
14: 0.0,
15: 0.0,
16: 220.94,
17: 727.5199999999995,
18: 2500.96999999999,
19: 4414.00999999998,
20: 15.0,
21: 196.71,
22: 2170.1,
23: 9745.24999999997,
24: 126.55,
25: 290.2,
26: 146.01,
27: 233.0,
28: 0.0,
29: 973.18,
30: 1658.940000000002}}).set_index(['group','category'])
df2 = pd.DataFrame.from_dict({'group': {0: 'total_full',
1: 'total_full',
2: 'A',
3: 'A',
4: 'B',
5: 'B',
6: 'C',
7: 'C',
8: 'D',
9: 'D',
10: 'Apple_total',
11: 'Apple_total',
12: 'A',
13: 'A',
14: 'B',
15: 'B',
16: 'C',
17: 'C',
18: 'D',
19: 'D',
20: 'Amazon_total',
21: 'Amazon_total',
22: 'A',
23: 'A',
24: 'B',
25: 'B',
26: 'C',
27: 'C',
28: 'D',
29: 'D',
30: 'Google_total',
31: 'Google_total',
32: 'A',
33: 'A',
34: 'B',
35: 'B',
36: 'C',
37: 'C',
38: 'D',
39: 'D',
40: 'Facebook_total',
41: 'Facebook_total',
42: 'A',
43: 'A',
44: 'B',
45: 'B',
46: 'C',
47: 'C',
48: 'D',
49: 'D',
50: 'Netflix_total',
51: 'Netflix_total',
52: 'A',
53: 'A',
54: 'B',
55: 'B',
56: 'C',
57: 'C',
58: 'D',
59: 'D',
60: 'Tesla_total',
61: 'Tesla_total',
62: 'A',
63: 'A',
64: 'B',
65: 'B',
66: 'C',
67: 'C',
68: 'D',
69: 'D',
70: 'Uber_total',
71: 'Uber_total',
72: 'A',
73: 'A',
74: 'B',
75: 'B',
76: 'C',
77: 'C',
78: 'D',
79: 'D'},
'category': {0: 'total_full',
1: 'total_full',
2: 'group_total',
3: 'group_total',
4: 'group_total',
5: 'group_total',
6: 'group_total',
7: 'group_total',
8: 'group_total',
9: 'group_total',
10: 'Apple_total',
11: 'Apple_total',
12: 'Apple',
13: 'Apple',
14: 'Apple',
15: 'Apple',
16: 'Apple',
17: 'Apple',
18: 'Apple',
19: 'Apple',
20: 'Amazon_total',
21: 'Amazon_total',
22: 'Amazon',
23: 'Amazon',
24: 'Amazon',
25: 'Amazon',
26: 'Amazon',
27: 'Amazon',
28: 'Amazon',
29: 'Amazon',
30: 'Google_total',
31: 'Google_total',
32: 'Google',
33: 'Google',
34: 'Google',
35: 'Google',
36: 'Google',
37: 'Google',
38: 'Google',
39: 'Google',
40: 'Facebook_total',
41: 'Facebook_total',
42: 'Facebook',
43: 'Facebook',
44: 'Facebook',
45: 'Facebook',
46: 'Facebook',
47: 'Facebook',
48: 'Facebook',
49: 'Facebook',
50: 'Netflix_total',
51: 'Netflix_total',
52: 'Netflix',
53: 'Netflix',
54: 'Netflix',
55: 'Netflix',
56: 'Netflix',
57: 'Netflix',
58: 'Netflix',
59: 'Netflix',
60: 'Tesla_total',
61: 'Tesla_total',
62: 'Tesla',
63: 'Tesla',
64: 'Tesla',
65: 'Tesla',
66: 'Tesla',
67: 'Tesla',
68: 'Tesla',
69: 'Tesla',
70: 'Uber_total',
71: 'Uber_total',
72: 'Uber',
73: 'Uber',
74: 'Uber',
75: 'Uber',
76: 'Uber',
77: 'Uber',
78: 'Uber',
79: 'Uber'},
'type': {0: 'Sales_1',
1: 'Sales_2',
2: 'Sales_1',
3: 'Sales_2',
4: 'Sales_1',
5: 'Sales_2',
6: 'Sales_1',
7: 'Sales_2',
8: 'Sales_1',
9: 'Sales_2',
10: 'Sales_1',
11: 'Sales_2',
12: 'Sales_1',
13: 'Sales_2',
14: 'Sales_1',
15: 'Sales_2',
16: 'Sales_1',
17: 'Sales_2',
18: 'Sales_1',
19: 'Sales_2',
20: 'Sales_1',
21: 'Sales_2',
22: 'Sales_1',
23: 'Sales_2',
24: 'Sales_1',
25: 'Sales_2',
26: 'Sales_1',
27: 'Sales_2',
28: 'Sales_1',
29: 'Sales_2',
30: 'Sales_1',
31: 'Sales_2',
32: 'Sales_1',
33: 'Sales_2',
34: 'Sales_1',
35: 'Sales_2',
36: 'Sales_1',
37: 'Sales_2',
38: 'Sales_1',
39: 'Sales_2',
40: 'Sales_1',
41: 'Sales_2',
42: 'Sales_1',
43: 'Sales_2',
44: 'Sales_1',
45: 'Sales_2',
46: 'Sales_1',
47: 'Sales_2',
48: 'Sales_1',
49: 'Sales_2',
50: 'Sales_1',
51: 'Sales_2',
52: 'Sales_1',
53: 'Sales_2',
54: 'Sales_1',
55: 'Sales_2',
56: 'Sales_1',
57: 'Sales_2',
58: 'Sales_1',
59: 'Sales_2',
60: 'Sales_1',
61: 'Sales_2',
62: 'Sales_1',
63: 'Sales_2',
64: 'Sales_1',
65: 'Sales_2',
66: 'Sales_1',
67: 'Sales_2',
68: 'Sales_1',
69: 'Sales_2',
70: 'Sales_1',
71: 'Sales_2',
72: 'Sales_1',
73: 'Sales_2',
74: 'Sales_1',
75: 'Sales_2',
76: 'Sales_1',
77: 'Sales_2',
78: 'Sales_1',
79: 'Sales_2'},
'2021-06-28': {0: 67.5277641202152,
1: 82.7854700135998,
2: 21.50082266792856,
3: 22.03644997199996,
4: 64.460440147,
5: 10.1060499896,
6: 65.1530371974946,
7: 50.6429700519999,
8: 56.413464107792045,
9: 0,
10: 17.48074540313092,
11: 26.8376199976,
12: 52.172,
13: 61.16600000040001,
14: 20.9447844,
15: 40.69122000000001,
16: 83.55718929717925,
17: 14.98039999719995,
18: 20.806771705951697,
19: np.nan,
20: 18.3766353690825,
21: 12.82565001479992,
22: 52.425508769690694,
23: 25.661999978399994,
24: 17.88071596,
25: 24.384659998799997,
26: 91.10086982794643,
27: 12.77899003759993,
28: 16.969540811445366,
29: np.nan,
30: 18.8795397517309,
31: 26.73017999840005,
32: 53.52039700062155,
33: 58.81199999639999,
34: 12.1243325,
35: 24.0544100028,
36: 55.94068246571674,
37: 133.86376999920006,
38: 7.294127785392621,
39: np.nan,
40: 6.07807089184563,
41: 7.27483001599998,
42: 2.300470581874837,
43: 30.71300000639998,
44: 5.810764652,
45: 12.333119997600003,
46: 25.475930745418292,
47: 64.228710012,
48: 9.490904912552498,
49: np.nan,
50: 8.184780211399392,
51: 24.59321999400001,
52: 6.807138946302334,
53: 12.0879999972,
54: 0.869207661,
55: 0.324,
56: 0.5084336040970575,
57: 12.181219996800007,
58: 0,
59: np.nan,
60: 9.293956915067886,
61: 11.171379993599999,
62: 6.384936971649232,
63: 3.657999996,
64: 0.913782413,
65: 1.9992000012000002,
66: 1.5322078073061867,
67: 5.514179996399999,
68: 0.4630297231124678,
69: np.nan,
70: 36.23403557795798,
71: 53.35258999919999,
72: 21.890370397789923,
73: 9.937449997200002,
74: 5.916852561,
75: 6.319439989199998,
76: 7.03772344983066,
77: 37.095700012799995,
78: 1.3890891693374032,
79: np.nan},
'2021-07-05': {0: 65.4690491915759,
1: 98.5235100112003,
2: 21.4573181155924,
3: 241.06741999679997,
4: 67.481716829,
5: 11.60325000040002,
6: 27.5807099999998,
7: 65.8528400140003,
8: 58.949304246983736,
9: 0.0,
10: 185.65887577993723,
11: 318.9965699964001,
12: 54.517,
13: 66.55265999039996,
14: 21.92632044,
15: 43.67116000320002,
16: 87.47349898707688,
17: 208.7727500028001,
18: 21.742056352860352,
19: np.nan,
20: 16.6038963173654,
21: 25.28952001920013,
22: 54.7820864335212,
23: 36.75802000560001,
24: 18.71872129,
25: 30.1634600016,
26: 95.37075040035738,
27: 138.3680400120001,
28: 17.73233819348684,
29: np.nan,
30: 14.80302342121337,
31: 251.83851001200003,
32: 55.926190956481534,
33: 72.4443400032,
34: 12.69221484,
35: 26.032340003999998,
36: 58.56261169338368,
37: 153.36183000480003,
38: 7.622005931348156,
39: np.nan,
40: 72.24367956241771,
41: 14.83083001279999,
42: 29.5726042895728,
43: 38.723000005199985,
44: 6.083562133,
45: 12.845630001599998,
46: 26.66998281055652,
47: 63.26220000600001,
48: 9.917530329288393,
49: np.nan,
50: 8.555606693927,
51: 23.802009994800002,
52: 7.113126469779095,
53: 7.206999998399999,
54: 0.910216433,
55: 1.4089999991999997,
56: 0.5322637911479053,
57: 15.186009997200001,
58: 0.0,
59: np.nan,
60: 9.716385738295367,
61: 14.7327399948,
62: 6.671946105284065,
63: 5.691999996,
64: 0.956574175,
65: 1.0203399996,
66: 1.6040220980113027,
67: 8.020399999199999,
68: 0.4838433599999999,
69: np.nan,
70: 37.88758167841983,
71: 59.03332998119994,
72: 22.874363860953647,
73: 13.690399997999998,
74: 6.194107518,
75: 6.4613199911999954,
76: 7.367580219466185,
77: 38.881609991999944,
78: 1.4515300799999995,
79: np.nan},
'2021-07-12': {0: 607.2971827405001,
1: 88.9671100664001,
2: 21.26749278974862,
3: 17.1524199804,
4: 64.471138092,
5: 89.84481002279999,
6: 26.2044999999998,
7: 51.9698800632001,
8: 5.354051858751745,
9: 0.0,
10: 177.42361595891452,
11: 287.5395700032,
12: 52.117,
13: 47.388199995600004,
14: 20.94835038,
15: 41.4250800048,
16: 83.57340667555117,
17: 198.72629000280003,
18: 20.784858903363354,
19: np.nan,
20: 178.323907459086,
21: 185.83897002839998,
22: 52.37029646474982,
23: 27.87144997800001,
24: 17.88339044,
25: 23.645340010799984,
26: 91.11855133792106,
27: 134.3221800396,
28: 16.95166921641509,
29: np.nan,
30: 128.82813286243115,
31: 192.6867300156,
32: 53.46403160619618,
33: 41.412320006399995,
34: 12.1261155,
35: 11.840830002000002,
36: 55.95153983444301,
37: 139.43358000720002,
38: 7.286445921791947,
39: np.nan,
40: 69.04410667683521,
41: 93.877410018,
42: 28.270665735943805,
43: 27.512680004399986,
44: 5.811656147,
45: 5.2319800032,
46: 25.480875296710053,
47: 61.132750010400024,
48: 9.480909497181356,
49: np.nan,
50: 8.178601399067174,
51: 17.6743199976,
52: 6.7999699585309585,
53: 6.131999998799999,
54: 0.870099156,
55: 0.6185600004,
56: 0.5085322845362154,
57: 10.923759998400003,
58: 0.0,
59: np.nan,
60: 9.287042311133577,
61: 19.966500000000007,
62: 6.378212628950804,
63: 6.524999997600001,
64: 0.913782413,
65: 1.9303400016,
66: 1.5325051891827732,
67: 11.511160000800006,
68: 0.4625420799999998,
69: np.nan,
70: 36.21177607303267,
71: 51.3836100036,
72: 21.86731639537707,
73: 10.310769999600003,
74: 5.917744056,
75: 5.152679999999999,
76: 7.039089381655591,
77: 35.920160003999996,
78: 1.3876262399999995,
79: np.nan}}).set_index(['group','category','type'])
f = lambda x: pd.to_datetime(x)
df = (df1.merge(df2.rename(columns=f).unstack(), left_index=True, right_index=True)
.sort_index(axis=1))
I am trying to add a column last_week_sales to each multiindex column.
So the total_sales from the previous week becomes last_week_sales in the following week in every multiindex column except for the first week as there are no data of the previous week.
What I've tried:
pd.merge(df.shift(-4, axis = 1).xs('total_sales', level=1,drop_level=False))
I am not sure how I can select only the second index, few answers suggested using .xs() but I am not sure how I would merge it on the date column, I tried shifting everything by -4 as then I get the desired week shift, but maybe there are better ways of achieving this.
Right now df.columns return
MultiIndex([('2021-06-28', 'Sales_1'),
('2021-06-28', 'Sales_2'),
('2021-06-28', 'total_orders'),
('2021-06-28', 'total_sales'),
('2021-07-05', 'Sales_1'),
('2021-07-05', 'Sales_2'),
('2021-07-05', 'total_orders'),
('2021-07-05', 'total_sales'),
('2021-07-12', 'Sales_1'),
('2021-07-12', 'Sales_2'),
('2021-07-12', 'total_orders'),
('2021-07-12', 'total_sales')])
And I would like to have:
MultiIndex([('2021-06-28', 'Sales_1'),
('2021-06-28', 'Sales_2'),
('2021-06-28', 'total_orders'),
('2021-06-28', 'total_sales'),
('2021-06-28', 'last_week_sales')
('2021-07-05', 'Sales_1'),
('2021-07-05', 'Sales_2'),
('2021-07-05', 'total_orders'),
('2021-07-05', 'total_sales'),
('2021-07-05', 'last_week_sales')
('2021-07-12', 'Sales_1'),
('2021-07-12', 'Sales_2'),
('2021-07-12', 'total_orders'),
('2021-07-12', 'total_sales'),
('2021-07-12', 'last_week_sales')])
Let us do in steps
Select the cross section of dataframe using loc
Shift the cross section along the columns axis
Rename total_sales to last_week_sales and combine the cross section with df
s = df.loc[:, (slice(None), 'total_sales')].shift(axis=1)
s = s.rename({'total_sales': 'last_week_sales'}, axis=1, level=1)
df.combine_first(s)
Related
I created a stacked bar chart and need to add a horizontal line but it doesn't show
What can be the problem?
Below is the code
import plotly.express as px
import pandas as pd
import numpy as np
import plotly.graph_objects as go
#creating array for days of the week
arr1=(['Mon. W1']*18)
arr2=(['Tue. W1']*18)
arr3=(['Wed. W1']*18)
arr4=(['Thu. W1']*18)
arr5=(['Fri. W1']*18)
arr6=(['Mon. W2']*18)
arr7=(['Tue. W2']*18)
arr8=(['Wed. W2']*18)
arr9=(['Thu. W2']*18)
arr10=(['Fri. W2']*18)
dates = np.concatenate((arr1,arr2,arr3,arr4,arr5,arr6,arr7,arr8,arr9,arr10))
#creating array for desk and meeting space population
from itertools import chain
from itertools import zip_longest
x = df3['Occupancy x Hour'].to_numpy()
y = df3['Population x Hour'].to_numpy()
#this is to change numpy array to normal array for further coding
values_array = list(filter(lambda x: x != '', chain.from_iterable(zip_longest(x, y, fillvalue = ''))))
#creating dictionary for the figure
df = pd.DataFrame(
dict(
day=dates,
time=['9am','9am','10am','10am','11am','11am','12pm','12pm','1pm','1pm','2pm','2pm','3pm','3pm','4pm','4pm','5pm','5pm']*10,
type=["Desk", "Meeting"]*90,
numbers=values_array,
)
)
#creating the bar chart
fig = go.Figure()
fig.update_layout(
template="simple_white",
xaxis=dict(title_text="Time"),
yaxis=dict(title_text="Population"),
barmode="stack",
)
colors = ["Blue","LimeGreen"]
#here adding time and day of the week on x-axis
for r, c in zip(df.type.unique(), colors):
plot_df = df[df.type == r]
fig.add_trace(
go.Bar(x=[plot_df.day, plot_df.time], y=plot_df.numbers, name=r, marker_color=c),
)
fig
df3_dictionary = {'Week': {0: 1.0,
1: 1.0,
2: 1.0,
3: 1.0,
4: 1.0,
5: 1.0,
6: 1.0,
7: 1.0,
8: 1.0,
9: 1.0,
10: 1.0,
11: 1.0,
12: 1.0,
13: 1.0,
14: 1.0,
15: 1.0,
16: 1.0,
17: 1.0,
18: 1.0,
19: 1.0,
20: 1.0,
21: 1.0,
22: 1.0,
23: 1.0,
24: 1.0,
25: 1.0,
26: 1.0,
27: 1.0,
28: 1.0,
29: 1.0,
30: 1.0,
31: 1.0,
32: 1.0,
33: 1.0,
34: 1.0,
35: 1.0,
36: 1.0,
37: 1.0,
38: 1.0,
39: 1.0,
40: 1.0,
41: 1.0,
42: 1.0,
43: 1.0,
44: 1.0,
45: 2.0,
46: 2.0,
47: 2.0,
48: 2.0,
49: 2.0,
50: 2.0,
51: 2.0,
52: 2.0,
53: 2.0,
54: 2.0,
55: 2.0,
56: 2.0,
57: 2.0,
58: 2.0,
59: 2.0,
60: 2.0,
61: 2.0,
62: 2.0,
63: 2.0,
64: 2.0,
65: 2.0,
66: 2.0,
67: 2.0,
68: 2.0,
69: 2.0,
70: 2.0,
71: 2.0,
72: 2.0,
73: 2.0,
74: 2.0,
75: 2.0,
76: 2.0,
77: 2.0,
78: 2.0,
79: 2.0,
80: 2.0,
81: 2.0,
82: 2.0,
83: 2.0,
84: 2.0,
85: 2.0,
86: 2.0,
87: 2.0,
88: 2.0,
89: 2.0},
'Day': {0: 'Monday',
1: 'Monday',
2: 'Monday',
3: 'Monday',
4: 'Monday',
5: 'Monday',
6: 'Monday',
7: 'Monday',
8: 'Monday',
9: 'Tuesday',
10: 'Tuesday',
11: 'Tuesday',
12: 'Tuesday',
13: 'Tuesday',
14: 'Tuesday',
15: 'Tuesday',
16: 'Tuesday',
17: 'Tuesday',
18: 'Wednesday',
19: 'Wednesday',
20: 'Wednesday',
21: 'Wednesday',
22: 'Wednesday',
23: 'Wednesday',
24: 'Wednesday',
25: 'Wednesday',
26: 'Wednesday',
27: 'Thursday',
28: 'Thursday',
29: 'Thursday',
30: 'Thursday',
31: 'Thursday',
32: 'Thursday',
33: 'Thursday',
34: 'Thursday',
35: 'Thursday',
36: 'Friday',
37: 'Friday',
38: 'Friday',
39: 'Friday',
40: 'Friday',
41: 'Friday',
42: 'Friday',
43: 'Friday',
44: 'Friday',
45: 'Monday',
46: 'Monday',
47: 'Monday',
48: 'Monday',
49: 'Monday',
50: 'Monday',
51: 'Monday',
52: 'Monday',
53: 'Monday',
54: 'Tuesday',
55: 'Tuesday',
56: 'Tuesday',
57: 'Tuesday',
58: 'Tuesday',
59: 'Tuesday',
60: 'Tuesday',
61: 'Tuesday',
62: 'Tuesday',
63: 'Wednesday',
64: 'Wednesday',
65: 'Wednesday',
66: 'Wednesday',
67: 'Wednesday',
68: 'Wednesday',
69: 'Wednesday',
70: 'Wednesday',
71: 'Wednesday',
72: 'Thursday',
73: 'Thursday',
74: 'Thursday',
75: 'Thursday',
76: 'Thursday',
77: 'Thursday',
78: 'Thursday',
79: 'Thursday',
80: 'Thursday',
81: 'Friday',
82: 'Friday',
83: 'Friday',
84: 'Friday',
85: 'Friday',
86: 'Friday',
87: 'Friday',
88: 'Friday',
89: 'Friday'},
'Time': {0: '9am',
1: '10am',
2: '11am',
3: '12pm',
4: '1pm',
5: '2pm',
6: '3pm',
7: '4pm',
8: '5pm',
9: '9am',
10: '10am',
11: '11am',
12: '12pm',
13: '1pm',
14: '2pm',
15: '3pm',
16: '4pm',
17: '5pm',
18: '9am',
19: '10am',
20: '11am',
21: '12pm',
22: '1pm',
23: '2pm',
24: '3pm',
25: '4pm',
26: '5pm',
27: '9am',
28: '10am',
29: '11am',
30: '12pm',
31: '1pm',
32: '2pm',
33: '3pm',
34: '4pm',
35: '5pm',
36: '9am',
37: '10am',
38: '11am',
39: '12pm',
40: '1pm',
41: '2pm',
42: '3pm',
43: '4pm',
44: '5pm',
45: '9am',
46: '10am',
47: '11am',
48: '12pm',
49: '1pm',
50: '2pm',
51: '3pm',
52: '4pm',
53: '5pm',
54: '9am',
55: '10am',
56: '11am',
57: '12pm',
58: '1pm',
59: '2pm',
60: '3pm',
61: '4pm',
62: '5pm',
63: '9am',
64: '10am',
65: '11am',
66: '12pm',
67: '1pm',
68: '2pm',
69: '3pm',
70: '4pm',
71: '5pm',
72: '9am',
73: '10am',
74: '11am',
75: '12pm',
76: '1pm',
77: '2pm',
78: '3pm',
79: '4pm',
80: '5pm',
81: '9am',
82: '10am',
83: '11am',
84: '12pm',
85: '1pm',
86: '2pm',
87: '3pm',
88: '4pm',
89: '5pm'},
'Occupancy x Hour': {0: 1378.0,
1: 1369.0,
2: 1372.0,
3: 1261.0,
4: 1087.0,
5: 1355.0,
6: 1383.0,
7: 1325.0,
8: 1050.0,
9: 1313.0,
10: 1347.0,
11: 1323.0,
12: 1202.0,
13: 1033.0,
14: 1237.0,
15: 1324.0,
16: 1352.0,
17: 1108.0,
18: 1217.0,
19: 1276.0,
20: 1365.0,
21: 1204.0,
22: 977.0,
23: 1199.0,
24: 1331.0,
25: 1293.0,
26: 1159.0,
27: 1220.0,
28: 1327.0,
29: 1354.0,
30: 1257.0,
31: 982.0,
32: 1199.0,
33: 1218.0,
34: 1271.0,
35: 1101.0,
36: 1139.0,
37: 1207.0,
38: 1259.0,
39: 1189.0,
40: 903.0,
41: 1171.0,
42: 1193.0,
43: 1239.0,
44: 899.0,
45: 1220.0,
46: 1357.0,
47: 1336.0,
48: 1188.0,
49: 1032.0,
50: 1261.0,
51: 1330.0,
52: 1267.0,
53: 1074.0,
54: 1301.0,
55: 1337.0,
56: 1329.0,
57: 1247.0,
58: 970.0,
59: 1233.0,
60: 1271.0,
61: 1246.0,
62: 1063.0,
63: 1210.0,
64: 1288.0,
65: 1331.0,
66: 1220.0,
67: 948.0,
68: 1273.0,
69: 1289.0,
70: 1329.0,
71: 1153.0,
72: 1213.0,
73: 1248.0,
74: 1272.0,
75: 1190.0,
76: 890.0,
77: 1199.0,
78: 1284.0,
79: 1233.0,
80: 1102.0,
81: 1110.0,
82: 1210.0,
83: 1175.0,
84: 1083.0,
85: 807.0,
86: 1101.0,
87: 1188.0,
88: 1181.0,
89: 857.0},
'Population x Hour': {0: 339.0,
1: 516.0,
2: 564.0,
3: 616.0,
4: 637.0,
5: 548.0,
6: 582.0,
7: 527.0,
8: 341.0,
9: 457.0,
10: 711.0,
11: 731.0,
12: 685.0,
13: 747.0,
14: 735.0,
15: 723.0,
16: 657.0,
17: 388.0,
18: 497.0,
19: 703.0,
20: 690.0,
21: 758.0,
22: 759.0,
23: 745.0,
24: 686.0,
25: 633.0,
26: 374.0,
27: 465.0,
28: 588.0,
29: 648.0,
30: 603.0,
31: 663.0,
32: 687.0,
33: 613.0,
34: 597.0,
35: 262.0,
36: 333.0,
37: 477.0,
38: 521.0,
39: 417.0,
40: 443.0,
41: 513.0,
42: 456.0,
43: 389.0,
44: 159.0,
45: 388.0,
46: 584.0,
47: 646.0,
48: 635.0,
49: 640.0,
50: 643.0,
51: 592.0,
52: 496.0,
53: 282.0,
54: 431.0,
55: 677.0,
56: 646.0,
57: 623.0,
58: 717.0,
59: 674.0,
60: 604.0,
61: 553.0,
62: 348.0,
63: 539.0,
64: 724.0,
65: 651.0,
66: 635.0,
67: 729.0,
68: 600.0,
69: 611.0,
70: 596.0,
71: 353.0,
72: 456.0,
73: 673.0,
74: 639.0,
75: 690.0,
76: 655.0,
77: 616.0,
78: 663.0,
79: 576.0,
80: 340.0,
81: 394.0,
82: 518.0,
83: 527.0,
84: 475.0,
85: 466.0,
86: 452.0,
87: 421.0,
88: 288.0,
89: 181.0}}
This code gives this result
Then, i am trying to add a line but it doesn't show
#finding minimum of the population
tot_popul = x+y
min(tot_popul)
#here, I am trying to plot minimum line but it doesn't show
fig.add_hline(y=min(tot_popul))
fig.show()
I need a horizontal line with minimum values
I have two dataframes with multi indexes and dates as a columns:
df1
df1 = pd.DataFrame.from_dict({('group', ''): {0: 'A',
1: 'A',
2: 'A',
3: 'A',
4: 'A',
5: 'A',
6: 'A',
7: 'A',
8: 'B',
9: 'B',
10: 'B',
11: 'B',
12: 'B',
13: 'B',
14: 'B',
15: 'B',
16: 'C',
17: 'C',
18: 'C',
19: 'C',
20: 'C',
21: 'C',
22: 'C',
23: 'C',
24: 'D',
25: 'D',
26: 'D',
27: 'D',
28: 'D',
29: 'D',
30: 'D'},
('category', ''): {0: 'Apple',
1: 'Amazon',
2: 'Google',
3: 'Netflix',
4: 'Facebook',
5: 'Uber',
6: 'Tesla',
7: 'total',
8: 'Apple',
9: 'Amazon',
10: 'Google',
11: 'Netflix',
12: 'Facebook',
13: 'Uber',
14: 'Tesla',
15: 'total',
16: 'Apple',
17: 'Amazon',
18: 'Google',
19: 'Netflix',
20: 'Facebook',
21: 'Uber',
22: 'Tesla',
23: 'total',
24: 'Apple',
25: 'Amazon',
26: 'Google',
27: 'Netflix',
28: 'Uber',
29: 'Tesla',
30: 'total'},
(pd.Timestamp('2021-06-28 00:00:00'), 'total_orders'): {0: 88.0,
1: 66.0,
2: 191.0,
3: 558.0,
4: 12.0,
5: 4.0,
6: 56.0,
7: 975.0,
8: 90.0,
9: 26.0,
10: 49.0,
11: 250.0,
12: 7.0,
13: 2.0,
14: 44.0,
15: 468.0,
16: 36.0,
17: 52.0,
18: 94.0,
19: 750.0,
20: 10.0,
21: 0.0,
22: 52.0,
23: 994.0,
24: 16.0,
25: 22.0,
26: 5.0,
27: 57.0,
28: 3.0,
29: 33.0,
30: 136.0},
(pd.Timestamp('2021-06-28 00:00:00'), 'total_sales'): {0: 4603.209999999999,
1: 2485.059999999998,
2: 4919.39999999998,
3: 6097.77,
4: 31.22,
5: 155.71,
6: 3484.99,
7: 17237.35999999996,
8: 561.54,
9: 698.75,
10: 1290.13,
11: 4292.68000000001,
12: 947.65,
13: 329.0,
14: 2889.65,
15: 9989.4,
16: 330.8899999999994,
17: 2076.26,
18: 2982.270000000004,
19: 11978.62000000002,
20: 683.0,
21: 0.0,
22: 3812.16999999999,
23: 20963.21000000002,
24: 234.4900000000002,
25: 896.1,
26: 231.0,
27: 893.810000000001,
28: 129.0,
29: 1712.329999999998,
30: 4106.729999999996},
(pd.Timestamp('2021-07-05 00:00:00'), 'total_orders'): {0: 109.0,
1: 48.0,
2: 174.0,
3: 592.0,
4: 13.0,
5: 5.0,
6: 43.0,
7: 984.0,
8: 62.0,
9: 13.0,
10: 37.0,
11: 196.0,
12: 8.0,
13: 1.0,
14: 3.0,
15: 30.0,
16: 76.0,
17: 5.0,
18: 147.0,
19: 88.0,
20: 8.0,
21: 1.0,
22: 78.0,
23: 1248.0,
24: 1.0,
25: 18.0,
26: 23.0,
27: 83.0,
28: 0.0,
29: 29.0,
30: 154.0},
(pd.Timestamp('2021-07-05 00:00:00'), 'total_sales'): {0: 3453.02,
1: 17868.730000000003,
2: 44707.82999999999,
3: 61425.99,
4: 1261.0,
5: 1914.6000000000001,
6: 24146.09,
7: 154777.25999999998,
8: 6201.489999999999,
9: 5513.960000000001,
10: 9645.87,
11: 25086.785,
12: 663.0,
13: 448.61,
14: 26332.7,
15: 73892.415,
16: 556.749999999999,
17: 1746.859999999997,
18: 4103.219999999994,
19: 15571.52000000008,
20: 86.0,
21: 69.0,
22: 5882.759999999995,
23: 26476.11000000004,
24: 53.0,
25: 801.220000000001,
26: 684.56,
27: 1232.600000000002,
28: 0.0,
29: 15902.1,
30: 43943.48},
(pd.Timestamp('2021-07-12 00:00:00'), 'total_orders'): {0: 32.0,
1: 15.0,
2: 89.0,
3: 239.0,
4: 2.0,
5: 3.0,
6: 20.0,
7: 400.0,
8: 0.0,
9: 0.0,
10: 0.0,
11: 0.0,
12: 0.0,
13: 0.0,
14: 0.0,
15: 0.0,
16: 21.0,
17: 14.0,
18: 58.0,
19: 281.0,
20: 3.0,
21: 3.0,
22: 33.0,
23: 413.0,
24: 7.0,
25: 6.0,
26: 4.0,
27: 13.0,
28: 0.0,
29: 18.0,
30: 48.0},
(pd.Timestamp('2021-07-12 00:00:00'), 'total_sales'): {0: 2147.7000000000003,
1: 4767.3,
2: 2399.300000000003,
3: 3137.440000000002,
4: 178.0,
5: 866.61,
6: 10639.03,
7: 73235.38,
8: 0.0,
9: 0.0,
10: 0.0,
11: 0.0,
12: 0.0,
13: 0.0,
14: 0.0,
15: 0.0,
16: 220.94,
17: 727.5199999999995,
18: 2500.96999999999,
19: 4414.00999999998,
20: 15.0,
21: 196.71,
22: 2170.1,
23: 9745.24999999997,
24: 126.55,
25: 290.2,
26: 146.01,
27: 233.0,
28: 0.0,
29: 973.18,
30: 1658.940000000002}}).set_index(['group','category'])
df2
df2 = pd.DataFrame.from_dict({'group': {0: 'total_full',
1: 'total_full',
2: 'A',
3: 'A',
4: 'B',
5: 'B',
6: 'C',
7: 'C',
8: 'D',
9: 'D',
10: 'Apple_total',
11: 'Apple_total',
12: 'A',
13: 'A',
14: 'B',
15: 'B',
16: 'C',
17: 'C',
18: 'D',
19: 'D',
20: 'Amazon_total',
21: 'Amazon_total',
22: 'A',
23: 'A',
24: 'B',
25: 'B',
26: 'C',
27: 'C',
28: 'D',
29: 'D',
30: 'Google_total',
31: 'Google_total',
32: 'A',
33: 'A',
34: 'B',
35: 'B',
36: 'C',
37: 'C',
38: 'D',
39: 'D',
40: 'Facebook_total',
41: 'Facebook_total',
42: 'A',
43: 'A',
44: 'B',
45: 'B',
46: 'C',
47: 'C',
48: 'D',
49: 'D',
50: 'Netflix_total',
51: 'Netflix_total',
52: 'A',
53: 'A',
54: 'B',
55: 'B',
56: 'C',
57: 'C',
58: 'D',
59: 'D',
60: 'Tesla_total',
61: 'Tesla_total',
62: 'A',
63: 'A',
64: 'B',
65: 'B',
66: 'C',
67: 'C',
68: 'D',
69: 'D',
70: 'Uber_total',
71: 'Uber_total',
72: 'A',
73: 'A',
74: 'B',
75: 'B',
76: 'C',
77: 'C',
78: 'D',
79: 'D'},
'category': {0: 'total_full',
1: 'total_full',
2: 'group_total',
3: 'group_total',
4: 'group_total',
5: 'group_total',
6: 'group_total',
7: 'group_total',
8: 'group_total',
9: 'group_total',
10: 'Apple_total',
11: 'Apple_total',
12: 'Apple',
13: 'Apple',
14: 'Apple',
15: 'Apple',
16: 'Apple',
17: 'Apple',
18: 'Apple',
19: 'Apple',
20: 'Amazon_total',
21: 'Amazon_total',
22: 'Amazon',
23: 'Amazon',
24: 'Amazon',
25: 'Amazon',
26: 'Amazon',
27: 'Amazon',
28: 'Amazon',
29: 'Amazon',
30: 'Google_total',
31: 'Google_total',
32: 'Google',
33: 'Google',
34: 'Google',
35: 'Google',
36: 'Google',
37: 'Google',
38: 'Google',
39: 'Google',
40: 'Facebook_total',
41: 'Facebook_total',
42: 'Facebook',
43: 'Facebook',
44: 'Facebook',
45: 'Facebook',
46: 'Facebook',
47: 'Facebook',
48: 'Facebook',
49: 'Facebook',
50: 'Netflix_total',
51: 'Netflix_total',
52: 'Netflix',
53: 'Netflix',
54: 'Netflix',
55: 'Netflix',
56: 'Netflix',
57: 'Netflix',
58: 'Netflix',
59: 'Netflix',
60: 'Tesla_total',
61: 'Tesla_total',
62: 'Tesla',
63: 'Tesla',
64: 'Tesla',
65: 'Tesla',
66: 'Tesla',
67: 'Tesla',
68: 'Tesla',
69: 'Tesla',
70: 'Uber_total',
71: 'Uber_total',
72: 'Uber',
73: 'Uber',
74: 'Uber',
75: 'Uber',
76: 'Uber',
77: 'Uber',
78: 'Uber',
79: 'Uber'},
'type': {0: 'Sales_1',
1: 'Sales_2',
2: 'Sales_1',
3: 'Sales_2',
4: 'Sales_1',
5: 'Sales_2',
6: 'Sales_1',
7: 'Sales_2',
8: 'Sales_1',
9: 'Sales_2',
10: 'Sales_1',
11: 'Sales_2',
12: 'Sales_1',
13: 'Sales_2',
14: 'Sales_1',
15: 'Sales_2',
16: 'Sales_1',
17: 'Sales_2',
18: 'Sales_1',
19: 'Sales_2',
20: 'Sales_1',
21: 'Sales_2',
22: 'Sales_1',
23: 'Sales_2',
24: 'Sales_1',
25: 'Sales_2',
26: 'Sales_1',
27: 'Sales_2',
28: 'Sales_1',
29: 'Sales_2',
30: 'Sales_1',
31: 'Sales_2',
32: 'Sales_1',
33: 'Sales_2',
34: 'Sales_1',
35: 'Sales_2',
36: 'Sales_1',
37: 'Sales_2',
38: 'Sales_1',
39: 'Sales_2',
40: 'Sales_1',
41: 'Sales_2',
42: 'Sales_1',
43: 'Sales_2',
44: 'Sales_1',
45: 'Sales_2',
46: 'Sales_1',
47: 'Sales_2',
48: 'Sales_1',
49: 'Sales_2',
50: 'Sales_1',
51: 'Sales_2',
52: 'Sales_1',
53: 'Sales_2',
54: 'Sales_1',
55: 'Sales_2',
56: 'Sales_1',
57: 'Sales_2',
58: 'Sales_1',
59: 'Sales_2',
60: 'Sales_1',
61: 'Sales_2',
62: 'Sales_1',
63: 'Sales_2',
64: 'Sales_1',
65: 'Sales_2',
66: 'Sales_1',
67: 'Sales_2',
68: 'Sales_1',
69: 'Sales_2',
70: 'Sales_1',
71: 'Sales_2',
72: 'Sales_1',
73: 'Sales_2',
74: 'Sales_1',
75: 'Sales_2',
76: 'Sales_1',
77: 'Sales_2',
78: 'Sales_1',
79: 'Sales_2'},
'2021-06-28': {0: 67.5277641202152,
1: 82.7854700135998,
2: 21.50082266792856,
3: 22.03644997199996,
4: 64.460440147,
5: 10.1060499896,
6: 65.1530371974946,
7: 50.6429700519999,
8: 56.413464107792045,
9: 0,
10: 17.48074540313092,
11: 26.8376199976,
12: 52.172,
13: 61.16600000040001,
14: 20.9447844,
15: 40.69122000000001,
16: 83.55718929717925,
17: 14.98039999719995,
18: 20.806771705951697,
19: np.nan,
20: 18.3766353690825,
21: 12.82565001479992,
22: 52.425508769690694,
23: 25.661999978399994,
24: 17.88071596,
25: 24.384659998799997,
26: 91.10086982794643,
27: 12.77899003759993,
28: 16.969540811445366,
29: np.nan,
30: 18.8795397517309,
31: 26.73017999840005,
32: 53.52039700062155,
33: 58.81199999639999,
34: 12.1243325,
35: 24.0544100028,
36: 55.94068246571674,
37: 133.86376999920006,
38: 7.294127785392621,
39: np.nan,
40: 6.07807089184563,
41: 7.27483001599998,
42: 2.300470581874837,
43: 30.71300000639998,
44: 5.810764652,
45: 12.333119997600003,
46: 25.475930745418292,
47: 64.228710012,
48: 9.490904912552498,
49: np.nan,
50: 8.184780211399392,
51: 24.59321999400001,
52: 6.807138946302334,
53: 12.0879999972,
54: 0.869207661,
55: 0.324,
56: 0.5084336040970575,
57: 12.181219996800007,
58: 0,
59: np.nan,
60: 9.293956915067886,
61: 11.171379993599999,
62: 6.384936971649232,
63: 3.657999996,
64: 0.913782413,
65: 1.9992000012000002,
66: 1.5322078073061867,
67: 5.514179996399999,
68: 0.4630297231124678,
69: np.nan,
70: 36.23403557795798,
71: 53.35258999919999,
72: 21.890370397789923,
73: 9.937449997200002,
74: 5.916852561,
75: 6.319439989199998,
76: 7.03772344983066,
77: 37.095700012799995,
78: 1.3890891693374032,
79: np.nan},
'2021-07-05': {0: 65.4690491915759,
1: 98.5235100112003,
2: 21.4573181155924,
3: 241.06741999679997,
4: 67.481716829,
5: 11.60325000040002,
6: 27.5807099999998,
7: 65.8528400140003,
8: 58.949304246983736,
9: 0.0,
10: 185.65887577993723,
11: 318.9965699964001,
12: 54.517,
13: 66.55265999039996,
14: 21.92632044,
15: 43.67116000320002,
16: 87.47349898707688,
17: 208.7727500028001,
18: 21.742056352860352,
19: np.nan,
20: 16.6038963173654,
21: 25.28952001920013,
22: 54.7820864335212,
23: 36.75802000560001,
24: 18.71872129,
25: 30.1634600016,
26: 95.37075040035738,
27: 138.3680400120001,
28: 17.73233819348684,
29: np.nan,
30: 14.80302342121337,
31: 251.83851001200003,
32: 55.926190956481534,
33: 72.4443400032,
34: 12.69221484,
35: 26.032340003999998,
36: 58.56261169338368,
37: 153.36183000480003,
38: 7.622005931348156,
39: np.nan,
40: 72.24367956241771,
41: 14.83083001279999,
42: 29.5726042895728,
43: 38.723000005199985,
44: 6.083562133,
45: 12.845630001599998,
46: 26.66998281055652,
47: 63.26220000600001,
48: 9.917530329288393,
49: np.nan,
50: 8.555606693927,
51: 23.802009994800002,
52: 7.113126469779095,
53: 7.206999998399999,
54: 0.910216433,
55: 1.4089999991999997,
56: 0.5322637911479053,
57: 15.186009997200001,
58: 0.0,
59: np.nan,
60: 9.716385738295367,
61: 14.7327399948,
62: 6.671946105284065,
63: 5.691999996,
64: 0.956574175,
65: 1.0203399996,
66: 1.6040220980113027,
67: 8.020399999199999,
68: 0.4838433599999999,
69: np.nan,
70: 37.88758167841983,
71: 59.03332998119994,
72: 22.874363860953647,
73: 13.690399997999998,
74: 6.194107518,
75: 6.4613199911999954,
76: 7.367580219466185,
77: 38.881609991999944,
78: 1.4515300799999995,
79: np.nan},
'2021-07-12': {0: 607.2971827405001,
1: 88.9671100664001,
2: 21.26749278974862,
3: 17.1524199804,
4: 64.471138092,
5: 89.84481002279999,
6: 26.2044999999998,
7: 51.9698800632001,
8: 5.354051858751745,
9: 0.0,
10: 177.42361595891452,
11: 287.5395700032,
12: 52.117,
13: 47.388199995600004,
14: 20.94835038,
15: 41.4250800048,
16: 83.57340667555117,
17: 198.72629000280003,
18: 20.784858903363354,
19: np.nan,
20: 178.323907459086,
21: 185.83897002839998,
22: 52.37029646474982,
23: 27.87144997800001,
24: 17.88339044,
25: 23.645340010799984,
26: 91.11855133792106,
27: 134.3221800396,
28: 16.95166921641509,
29: np.nan,
30: 128.82813286243115,
31: 192.6867300156,
32: 53.46403160619618,
33: 41.412320006399995,
34: 12.1261155,
35: 11.840830002000002,
36: 55.95153983444301,
37: 139.43358000720002,
38: 7.286445921791947,
39: np.nan,
40: 69.04410667683521,
41: 93.877410018,
42: 28.270665735943805,
43: 27.512680004399986,
44: 5.811656147,
45: 5.2319800032,
46: 25.480875296710053,
47: 61.132750010400024,
48: 9.480909497181356,
49: np.nan,
50: 8.178601399067174,
51: 17.6743199976,
52: 6.7999699585309585,
53: 6.131999998799999,
54: 0.870099156,
55: 0.6185600004,
56: 0.5085322845362154,
57: 10.923759998400003,
58: 0.0,
59: np.nan,
60: 9.287042311133577,
61: 19.966500000000007,
62: 6.378212628950804,
63: 6.524999997600001,
64: 0.913782413,
65: 1.9303400016,
66: 1.5325051891827732,
67: 11.511160000800006,
68: 0.4625420799999998,
69: np.nan,
70: 36.21177607303267,
71: 51.3836100036,
72: 21.86731639537707,
73: 10.310769999600003,
74: 5.917744056,
75: 5.152679999999999,
76: 7.039089381655591,
77: 35.920160003999996,
78: 1.3876262399999995,
79: np.nan}}).set_index(['group','category','type'])
I am trying to merge df2 on df1 by group, category, date (date is a column) so that my output would look like this:
I omitted the values from df2 of sales_1 & sales_2 in my desired output example, but those rows should be filled with the corresponding group and category values from df2.
2021-06-28 2021-07-05 2021-07-12
total_orders total_sales sales_1 sales_2 total_orders total_sales sales_1 sales_2 total_orders total_sales sales_1 sales_2
group category
A Apple 88.000 4,603.210
Amazon 66.000 2,485.060
Google 191.000 4,919.400
Netflix 558.000 6,097.770
Facebook 12.000 31.220
Uber 4.000 155.710
Tesla 56.000 3,484.990
total 975.000 17,237.360
B Apple 90.000 561.540
Amazon 26.000 698.750
Google 49.000 1,290.130
Netflix 250.000 4,292.680
Facebook 7.000 947.650
Uber 2.000 329.000
Tesla 44.000 2,889.650
total 468.000 9,989.400
C Apple 36.000 330.890
Amazon 52.000 2,076.260
Google 94.000 2,982.270
Netflix 750.000 11,978.620
Facebook 10.000 683.000
Uber 0.000 0.000
Tesla 52.000 3,812.170
total 994.000 20,963.210
D Apple 16.000 234.490
Amazon 22.000 896.100
Google 5.000 231.000
Netflix 57.000 893.810
Uber 3.000 129.000
Tesla 33.000 1,712.330
total 136.000 4,106.730
So that sales_1 & sales_2 are merged on group & category and are on the same date column. The total_x from df2 can be ignored as it can be calculated from the fields.
The total_values are not used in merge, only the ones after it.
What I've tried:
df1.reset_index().merge(df2.reset_index(), left_on=['group', 'category'], right_on=['group', 'category'])
Which throws a warning:
UserWarning: merging between different levels can give an unintended result (2 levels on the left,1 on the right)
And is not how I expect it to merge. How could I achieve my desired output?
Using
df = df1.merge(df2.unstack(), left_index=True, right_index=True)
Produces:
Is it then just reordering of columns as I want to have a unique date and 4 columns for it? Or it might be that one date has 00:00:00 to it?
Create DatetimeIndex in column in df2 first, then unstack and merge by MultiIndexes:
f = lambda x: pd.to_datetime(x)
df = (df1.merge(df2.rename(columns=f).unstack(), left_index=True, right_index=True)
.sort_index(axis=1))
print (df.head())
2021-06-28 2021-07-05 \
Sales_1 Sales_2 total_orders total_sales Sales_1
group category
A Apple 52.172000 61.166 88.0 4603.21 54.517000
Amazon 52.425509 25.662 66.0 2485.06 54.782086
Google 53.520397 58.812 191.0 4919.40 55.926191
Netflix 6.807139 12.088 558.0 6097.77 7.113126
Facebook 2.300471 30.713 12.0 31.22 29.572604
2021-07-12 \
Sales_2 total_orders total_sales Sales_1 Sales_2
group category
A Apple 66.55266 109.0 3453.02 52.117000 47.38820
Amazon 36.75802 48.0 17868.73 52.370296 27.87145
Google 72.44434 174.0 44707.83 53.464032 41.41232
Netflix 7.20700 592.0 61425.99 6.799970 6.13200
Facebook 38.72300 13.0 1261.00 28.270666 27.51268
total_orders total_sales
group category
A Apple 32.0 2147.70
Amazon 15.0 4767.30
Google 89.0 2399.30
Netflix 239.0 3137.44
Facebook 2.0 178.00
I generate the following plot:
By the following code:
data = {'BestFit_rej_ratio': {0: 0.1975987994, 1: 0.2006003002, 2: 0.1790895448, 3: 0.2216108054, 4: 0.1785892946, 5: 0.1890945473, 6: 0.1780890445, 7: 0.1780890445, 8: 0.2016008004, 9: 0.1900950475, 10: 0.1985992996, 11: 0.2031015508, 12: 0.2046023012, 13: 0.2071035518, 14: 0.1750875438, 15: 0.2166083042, 16: 0.1725862931, 17: 0.188094047, 18: 0.1870935468, 19: 0.1895947974, 20: 0.004502251126, 21: 0.006503251626, 22: 0.005002501251, 23: 0.006503251626, 24: 0.008004002001, 25: 0.006003001501, 26: 0.00300150075, 27: 0.005502751376, 28: 0.0100050025, 29: 0.005002501251, 30: 0.006003001501, 31: 0.005502751376, 32: 0.007503751876, 33: 0.005502751376, 34: 0.005502751376, 35: 0.005502751376, 36: 0.007503751876, 37: 0.005002501251, 38: 0.004002001001, 39: 0.009004502251, 40: 0.4172086043, 41: 0.4322161081, 42: 0.4017008504, 43: 0.4247123562, 44: 0.4292146073, 45: 0.4077038519, 46: 0.4282141071, 47: 0.4637318659, 48: 0.4392196098, 49: 0.4172086043, 50: 0.4187093547, 51: 0.4057028514, 52: 0.4287143572, 53: 0.4242121061, 54: 0.4347173587, 55: 0.4307153577, 56: 0.4102051026, 57: 0.4437218609, 58: 0.4212106053, 59: 0.4172086043}, 'MDP_rej_ratio': {0: 0.1660830415, 1: 0.1605802901, 2: 0.152076038, 3: 0.1885942971, 4: 0.152076038, 5: 0.1565782891, 6: 0.1445722861, 7: 0.1570785393, 8: 0.1705852926, 9: 0.1605802901, 10: 0.1740870435, 11: 0.1670835418, 12: 0.1805902951, 13: 0.1740870435, 14: 0.1460730365, 15: 0.1810905453, 16: 0.1425712856, 17: 0.1580790395, 18: 0.1455727864, 19: 0.1590795398, 20: 0.001500750375, 21: 0.00300150075, 22: 0.002501250625, 23: 0.002501250625, 24: 0.0020010005, 25: 0.002501250625, 26: 0.0020010005, 27: 0.001500750375, 28: 0.004002001001, 29: 0.00300150075, 30: 0.0020010005, 31: 0.0, 32: 0.004002001001, 33: 0.0005002501251, 34: 0.0020010005, 35: 0.0, 36: 0.004502251126, 37: 0.002501250625, 38: 0.001500750375, 39: 0.004002001001, 40: 0.3851925963, 41: 0.3851925963, 42: 0.4097048524, 43: 0.3756878439, 44: 0.4112056028, 45: 0.4212106053, 46: 0.3791895948, 47: 0.4127063532, 48: 0.4432216108, 49: 0.4152076038, 50: 0.3871935968, 51: 0.4197098549, 52: 0.3896948474, 53: 0.4107053527, 54: 0.4062031016, 55: 0.4252126063, 56: 0.4112056028, 57: 0.3931965983, 58: 0.4372186093, 59: 0.4157078539}, 'Q-Learning_rej_ratio': {0: 0.1790895448, 1: 0.1645822911, 2: 0.1545772886, 3: 0.1905952976, 4: 0.1510755378, 5: 0.1595797899, 6: 0.148074037, 7: 0.1575787894, 8: 0.1715857929, 9: 0.1590795398, 10: 0.1690845423, 11: 0.168084042, 12: 0.180090045, 13: 0.1785892946, 14: 0.1495747874, 15: 0.1815907954, 16: 0.1435717859, 17: 0.1685842921, 18: 0.1505752876, 19: 0.1670835418, 20: 0.001500750375, 21: 0.00300150075, 22: 0.002501250625, 23: 0.002501250625, 24: 0.0020010005, 25: 0.002501250625, 26: 0.0020010005, 27: 0.001500750375, 28: 0.004002001001, 29: 0.00300150075, 30: 0.0020010005, 31: 0.0, 32: 0.004002001001, 33: 0.0005002501251, 34: 0.0020010005, 35: 0.0, 36: 0.004502251126, 37: 0.002501250625, 38: 0.001500750375, 39: 0.004002001001, 40: 0.3856928464, 41: 0.4167083542, 42: 0.3786893447, 43: 0.4187093547, 44: 0.4157078539, 45: 0.392196098, 46: 0.4032016008, 47: 0.4452226113, 48: 0.4217108554, 49: 0.3876938469, 50: 0.4192096048, 51: 0.388194097, 52: 0.4122061031, 53: 0.4152076038, 54: 0.4172086043, 55: 0.4137068534, 56: 0.3956978489, 57: 0.4342171086, 58: 0.4082041021, 59: 0.4032016008}, 'Parametrized_factor': {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0, 5: 1.0, 6: 1.0, 7: 1.0, 8: 1.0, 9: 1.0, 10: 1.0, 11: 1.0, 12: 1.0, 13: 1.0, 14: 1.0, 15: 1.0, 16: 1.0, 17: 1.0, 18: 1.0, 19: 1.0, 20: 0.2, 21: 0.2, 22: 0.2, 23: 0.2, 24: 0.2, 25: 0.2, 26: 0.2, 27: 0.2, 28: 0.2, 29: 0.2, 30: 0.2, 31: 0.2, 32: 0.2, 33: 0.2, 34: 0.2, 35: 0.2, 36: 0.2, 37: 0.2, 38: 0.2, 39: 0.2, 40: 2.0, 41: 2.0, 42: 2.0, 43: 2.0, 44: 2.0, 45: 2.0, 46: 2.0, 47: 2.0, 48: 2.0, 49: 2.0, 50: 2.0, 51: 2.0, 52: 2.0, 53: 2.0, 54: 2.0, 55: 2.0, 56: 2.0, 57: 2.0, 58: 2.0, 59: 2.0}}
data2 = pd.DataFrame(data)
# figure size
plt.figure(figsize=(12, 8))
ax = sns.pointplot(y="BestFit_rej_ratio", x="Parametrized_factor", data=data2, linestyles='-.', color='g', capsize=.1, scale=.2, errwidth=.5)
ax = sns.pointplot(y="MDP_rej_ratio", x="Parametrized_factor", data=data2, linestyles='-', color='r', capsize=.12, scale=.2, errwidth=.5)
ax = sns.pointplot(y="Q-Learning_rej_ratio", x="Parametrized_factor", data=data2, linestyles=':', color='k', capsize=.15, scale=.5, errwidth=.5)
ax.legend(bbox_to_anchor=(1.15, 1), loc='upper left')
labels = ax.legend(['BestFit', 'MDP', 'Q-Learning'])
colors = ['green', 'red', 'black']
i = 0
for l in labels.get_texts():
l.set_color(colors[i])
i+=1
plt.setp(ax.get_legend().get_texts(), fontsize='12')
# for legend text
ax.set_ylabel('Rejection ratio')
ax.set_xlabel('Parametrized factor')
plt.show()
Problem is that the plot is not respecting the scale of the x-axis values (Parametrized_factor).
How can I solve it?
I want to plot a double y-axis plot where the user can select which variable to look at. I want the dropdown option to change the original y-axis, but also want the second y-axis to change with the variable change. The data comes from two dictionaries, where each dictionary has 2 keys which are dataframes. Here are the dicts:
df_vals.keys()
['corn','soybeans']
{'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-21 00:00:00'), 2: Timestamp('2020-09-22 00:00:00'), 3: Timestamp('2020-09-23 00:00:00'), 4: Timestamp('2020-09-24 00:00:00'), 5: Timestamp('2020-09-25 00:00:00'), 6: Timestamp('2020-09-26 00:00:00'), 7: Timestamp('2020-09-27 00:00:00'), 8: Timestamp('2020-09-28 00:00:00'), 9: Timestamp('2020-09-29 00:00:00'), 10: Timestamp('2020-09-30 00:00:00'), 11: Timestamp('2020-10-01 00:00:00'), 12: Timestamp('2020-10-02 00:00:00'), 13: Timestamp('2020-10-03 00:00:00'), 14: Timestamp('2020-10-04 00:00:00'), 15: Timestamp('2020-10-05 00:00:00')}, '2m_temp_24hdelta_prod': {0: -0.33056551535638423, 1: -0.06352654836543402, 2: -0.276225357129493, 3: -0.7788107233764435, 4: -0.12182345812042986, 5: 0.4844870528180379, 6: -0.7795401737865336, 7: -1.3736563255451468, 8: -0.7925949910485673, 9: -0.6084065411465024, 10: -0.6532739602739552, 11: -0.5334182358612463, 12: -0.3214601096392593, 13: 0.005672046711691303, 14: 0.294874775721931, 15: 0.0}, '2m_temp_24hdelta_area': {0: -0.2942234811255382, 1: -0.06695257736951654, 2: -0.2382484006633631, 3: -0.747444491858053, 4: -0.008792915536150941, 5: 0.25843822574146474, 6: -0.8653840134962728, 7: -1.3306357244341183, 8: -0.77807373911064, 9: -0.6101878063800394, 10: -0.6602593986352374, 11: -0.5377113682438022, 12: -0.3489377042704134, 13: -0.12997682663355925, 14: 0.08031697715852158, 15: 0.0}, 'total_precip_24hdelta_prod': {0: -1.4417379991236094, 1: -3.24276961794111, 2: -1.9549294932106442, 3: 1.0805492310759035, 4: -2.8572102912370547, 5: -0.6036102993252254, 6: 0.068152851219848, 7: -0.37760433118519804, 8: -0.2182212103223477, 9: 0.14385291749053375, 10: -0.09611101762074367, 11: -0.44170367466228744, 12: -0.9926136091953488, 13: -0.26638156415402015, 14: -0.0435076228174961, 15: 0.0}, 'total_precip_24hdelta_area': {0: -0.8969484573159082, 1: -2.002193332285897, 2: -1.3265684841453602, 3: 0.5232970017014504, 4: -1.9744318826572878, 5: -0.4756557183821801, 6: 0.09401319045911638, 7: -0.2480262049680989, 8: -0.16164720991353132, 9: 0.12918646107950632, 10: -0.025385234499880355, 11: -0.37094005589542123, 12: -0.7621485373750772, 13: -0.21974376949919702, 14: -0.06387744429696394, 15: 0.0}}
{'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-21 00:00:00'), 2: Timestamp('2020-09-22 00:00:00'), 3: Timestamp('2020-09-23 00:00:00'), 4: Timestamp('2020-09-24 00:00:00'), 5: Timestamp('2020-09-25 00:00:00'), 6: Timestamp('2020-09-26 00:00:00'), 7: Timestamp('2020-09-27 00:00:00'), 8: Timestamp('2020-09-28 00:00:00'), 9: Timestamp('2020-09-29 00:00:00'), 10: Timestamp('2020-09-30 00:00:00'), 11: Timestamp('2020-10-01 00:00:00'), 12: Timestamp('2020-10-02 00:00:00'), 13: Timestamp('2020-10-03 00:00:00'), 14: Timestamp('2020-10-04 00:00:00'), 15: Timestamp('2020-10-05 00:00:00')}, '2m_temp_24hdelta_prod': {0: -0.41072100441995785, 1: -0.11297222900273206, 2: -0.3134558546203517, 3: -0.7055797268403201, 4: -0.14038170579478787, 5: 0.2625117005223226, 6: -0.7101408224478941, 7: -1.2573241419225902, 8: -0.7906424533010389, 9: -0.661536032998284, 10: -0.6822789549363446, 11: -0.5744259308508103, 12: -0.4206210457410846, 13: -0.08431581171659296, 14: 0.2654961632050054, 15: 0.0}, '2m_temp_24hdelta_area': {0: -0.36772899690348704, 1: -0.05348366544356093, 2: -0.24183851104639115, 3: -0.6953305273210354, 4: -0.045424744173602496, 5: 0.19001500780368247, 6: -0.821935103347599, 7: -1.265563237441084, 8: -0.7328581189116925, 9: -0.6143048783236709, 10: -0.6633462127739507, 11: -0.5190203572096471, 12: -0.39498226425933547, 13: -0.10526773964830015, 14: 0.19258302497068705, 15: 0.0}, 'total_precip_24hdelta_prod': {0: -0.6776698356563055, 1: -1.7516299539550721, 2: -1.270815712012518, 3: 0.5996647217068156, 4: -2.2466045890287396, 5: -0.6706621597096377, 6: 0.06719919310410405, 7: -0.3572052717181586, 8: -0.2512178851633781, 9: 0.1313636195701381, 10: 0.08179245850142033, 11: -0.3036658888458674, 12: -0.8200237460316371, 13: -0.32927495598480583, 14: -0.08189579932441349, 15: 0.0}, 'total_precip_24hdelta_area': {0: -0.7530386453128719, 1: -1.7027556154743797, 2: -1.0907657669920294, 3: 0.429094034006764, 4: -1.9424324271143407, 5: -0.5370968484676638, 6: 0.044404490985521246, 7: -0.30794153270377544, 8: -0.2471378005907392, 9: 0.1212115468745879, 10: 0.07486462848670472, 11: -0.3507116185903665, 12: -0.7247205225779287, 13: -0.25431240691233936, 14: -0.06960793926681186, 15: 0.0}}
df_deltas.keys()
['corn','soybeans']
{'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-20 06:00:00'), 2: Timestamp('2020-09-20 12:00:00'), 3: Timestamp('2020-09-20 18:00:00'), 4: Timestamp('2020-09-21 00:00:00'), 5: Timestamp('2020-09-21 06:00:00'), 6: Timestamp('2020-09-21 12:00:00'), 7: Timestamp('2020-09-21 18:00:00'), 8: Timestamp('2020-09-22 00:00:00'), 9: Timestamp('2020-09-22 06:00:00'), 10: Timestamp('2020-09-22 12:00:00'), 11: Timestamp('2020-09-22 18:00:00'), 12: Timestamp('2020-09-23 00:00:00'), 13: Timestamp('2020-09-23 06:00:00'), 14: Timestamp('2020-09-23 12:00:00'), 15: Timestamp('2020-09-23 18:00:00'), 16: Timestamp('2020-09-24 00:00:00'), 17: Timestamp('2020-09-24 06:00:00'), 18: Timestamp('2020-09-24 12:00:00'), 19: Timestamp('2020-09-24 18:00:00'), 20: Timestamp('2020-09-25 00:00:00'), 21: Timestamp('2020-09-25 06:00:00'), 22: Timestamp('2020-09-25 12:00:00'), 23: Timestamp('2020-09-25 18:00:00'), 24: Timestamp('2020-09-26 00:00:00'), 25: Timestamp('2020-09-26 06:00:00'), 26: Timestamp('2020-09-26 12:00:00'), 27: Timestamp('2020-09-26 18:00:00'), 28: Timestamp('2020-09-27 00:00:00'), 29: Timestamp('2020-09-27 06:00:00'), 30: Timestamp('2020-09-27 12:00:00'), 31: Timestamp('2020-09-27 18:00:00'), 32: Timestamp('2020-09-28 00:00:00'), 33: Timestamp('2020-09-28 06:00:00'), 34: Timestamp('2020-09-28 12:00:00'), 35: Timestamp('2020-09-28 18:00:00'), 36: Timestamp('2020-09-29 00:00:00'), 37: Timestamp('2020-09-29 06:00:00'), 38: Timestamp('2020-09-29 12:00:00'), 39: Timestamp('2020-09-29 18:00:00'), 40: Timestamp('2020-09-30 00:00:00'), 41: Timestamp('2020-09-30 06:00:00'), 42: Timestamp('2020-09-30 12:00:00'), 43: Timestamp('2020-09-30 18:00:00'), 44: Timestamp('2020-10-01 00:00:00'), 45: Timestamp('2020-10-01 06:00:00'), 46: Timestamp('2020-10-01 12:00:00'), 47: Timestamp('2020-10-01 18:00:00'), 48: Timestamp('2020-10-02 00:00:00'), 49: Timestamp('2020-10-02 06:00:00'), 50: Timestamp('2020-10-02 12:00:00'), 51: Timestamp('2020-10-02 18:00:00'), 52: Timestamp('2020-10-03 00:00:00'), 53: Timestamp('2020-10-03 06:00:00'), 54: Timestamp('2020-10-03 12:00:00'), 55: Timestamp('2020-10-03 18:00:00'), 56: Timestamp('2020-10-04 00:00:00'), 57: Timestamp('2020-10-04 06:00:00'), 58: Timestamp('2020-10-04 12:00:00'), 59: Timestamp('2020-10-04 18:00:00'), 60: Timestamp('2020-10-05 00:00:00')}, '2m_temp_prod': {0: 299.346777266481, 1: 294.0395117035824, 2: 292.9592738522704, 3: 301.3180464757325, 4: 300.62356652087135, 5: 295.3372490145483, 6: 293.70255086586366, 7: 301.74835531223954, 8: 300.63094530701716, 9: 295.19553201608596, 10: 293.61613871139605, 11: 302.1631229776387, 12: 300.9153730135594, 13: 295.15968865817507, 14: 293.4150837111033, 15: 301.41874976967574, 16: 300.2591302298784, 17: 294.35648855874496, 18: 292.60893943975975, 19: 300.69793228145136, 20: 299.21051997362474, 21: 293.03793188187217, 22: 290.7864320360987, 23: 298.83351270175194, 24: 297.3528693941268, 25: 291.19369512544074, 26: 289.09521928196455, 27: 297.6441935083638, 28: 296.7296754953959, 29: 290.9897312443865, 30: 289.32126319033677, 31: 298.7574828448876, 32: 298.12901959834915, 33: 292.5899489699376, 34: 290.89859256270717, 35: 300.43330551865887, 36: 299.4213926560918, 37: 293.6473005538043, 38: 291.78953606425546, 39: 300.96031965551913, 40: 299.8616920790521, 41: 293.9476866306047, 42: 292.00448821963647, 43: 301.2204786022793, 44: 300.1545728526989, 45: 294.30968496479613, 46: 292.3264718663577, 47: 301.6422264431679, 48: 300.6382119018213, 49: 294.9066383821488, 50: 292.9206232319892, 51: 302.28532470110673, 52: 301.118337633183, 53: 295.580361365072, 54: 293.5071232611944, 55: 302.4993713158521, 56: 301.1771411161832, 57: 295.87429820309063, 58: 293.8387870006977, 59: 302.3844741742686, 60: 300.92076629492163}, '2m_temp_area': {0: 299.79923425166567, 1: 294.4433522483179, 2: 293.1829305163771, 3: 301.76751592578194, 4: 300.97964970416314, 5: 295.58816311209137, 6: 293.944118250348, 7: 302.20448177813586, 8: 301.0782745090335, 9: 295.36833103932497, 10: 293.7448705435944, 11: 302.2414068531493, 12: 300.97154909133104, 13: 295.09171791304016, 14: 293.29872586829305, 15: 301.63398450993316, 16: 300.39729350367077, 17: 294.4765532352668, 18: 292.6348308697987, 19: 300.7196467769189, 20: 299.2413397435659, 21: 293.1571305856655, 22: 290.9298399188299, 23: 299.0361571649767, 24: 297.6784967259681, 25: 291.6225850820778, 26: 289.5307387179231, 27: 298.1675193109706, 28: 297.2851193736129, 29: 291.6047803054954, 30: 289.8725165929944, 31: 299.2259541567033, 32: 298.5645974740215, 33: 292.9844928941141, 34: 291.16692080415885, 35: 300.6640689360243, 36: 299.63105315816887, 37: 293.7973759485704, 38: 291.8748714049971, 39: 301.07558737962773, 40: 299.9769492884242, 41: 294.06556034682825, 42: 292.0989825175383, 43: 301.3224275326778, 44: 300.2429318269633, 45: 294.4016189433437, 46: 292.39193470959646, 47: 301.691478296914, 48: 300.693790365317, 49: 294.95729295702677, 50: 292.94815058578274, 51: 302.1922658603409, 52: 301.01878139937173, 53: 295.47413908911483, 54: 293.41960123543845, 55: 302.34370446075303, 56: 301.05227283650527, 57: 295.72013507339597, 58: 293.6867376233815, 59: 302.19133411599717, 60: 300.81799340051333}, 'total_precip_prod': {0: 0.0, 1: 0.19106968995229195, 2: 0.1557650112297922, 3: 0.42176822127339436, 4: 0.3635719686978164, 5: 0.624238127750141, 6: 0.7363658332723646, 7: 0.6637602529624484, 8: 0.8303668371501847, 9: 0.9645353650727154, 10: 0.9080621631493283, 11: 0.7407109615632305, 12: 1.2188155467167008, 13: 1.4934816133864144, 14: 0.8673540204216558, 15: 0.4536446670226782, 16: 0.5838893851141779, 17: 0.28997017910749373, 18: 0.396575809101194, 19: 0.3017425722928852, 20: 0.2600037974259506, 21: 0.10090977019496428, 22: 0.1120663639424084, 23: 0.11820662603244433, 24: 0.11351422163952127, 25: 0.0354462928350286, 26: 0.08973231687769569, 27: 0.11707786940722151, 28: 0.07097838855834729, 29: 0.03411315769121203, 30: 0.09051350215127027, 31: 0.11314915610119855, 32: 0.14753233086329737, 33: 0.1845242398275337, 34: 0.2518174918229658, 35: 0.17011312187047897, 36: 0.2749232044764252, 37: 0.2972017724997405, 38: 0.3552475267861772, 39: 0.27943871692889416, 40: 0.31981605728486306, 41: 0.19735958986038185, 42: 0.2806487307465678, 43: 0.2830918175327961, 44: 0.3288561686915008, 45: 0.1744303376099874, 46: 0.30609645936303326, 47: 0.21925050665230758, 48: 0.20281755796768022, 49: 0.06620804878284778, 50: 0.17684099550656973, 51: 0.19853145136367492, 52: 0.2563854573673008, 53: 0.24201876323456878, 54: 0.41939251801295807, 55: 0.36402178359658277, 56: 0.37120895070913373, 57: 0.281792653746079, 58: 0.5868870658107626, 59: 0.4927117680726645, 60: 0.5223743530274055}, 'total_precip_area': {0: 0.0, 1: 0.2869521154242563, 2: 0.21660564402622137, 3: 0.4856913604264373, 4: 0.5011640941544891, 5: 0.7562519498474788, 6: 0.7839821183163472, 7: 0.5862595162666312, 8: 0.8974715199444484, 9: 0.9610750641626696, 10: 0.7601911282379429, 11: 0.793906823631679, 12: 1.2383530336279156, 13: 1.0049543280590305, 14: 0.6820852351772055, 15: 0.442434189821785, 16: 0.6589929874909368, 17: 0.32723035127408134, 18: 0.4144798865599254, 19: 0.368782410513661, 20: 0.36137157927969976, 21: 0.1635789497829729, 22: 0.16409778482825316, 23: 0.16768421904602382, 24: 0.1808376986943956, 25: 0.058153150056705245, 26: 0.1269072928484502, 27: 0.14562713451681256, 28: 0.11216762073388148, 29: 0.062161294677683845, 30: 0.13994272590442386, 31: 0.1662560753829063, 32: 0.20624170840852787, 33: 0.216927525300605, 34: 0.26804054777036235, 35: 0.20587583527311556, 36: 0.297848309035157, 37: 0.2836083045675833, 38: 0.33686407205543173, 39: 0.276288892940258, 40: 0.3569925386418611, 41: 0.2258142673918131, 42: 0.30458249604018844, 43: 0.2882872466330577, 44: 0.36861110970625127, 45: 0.1945528585156628, 46: 0.2996099093542968, 47: 0.2370841370242934, 48: 0.24429531409451738, 49: 0.09534765734716107, 50: 0.19399822393477686, 51: 0.24311804406545334, 52: 0.3062432174815857, 53: 0.27031885272433986, 54: 0.40763842665734645, 55: 0.3546261915245615, 56: 0.4085152708749088, 57: 0.30056439476727764, 58: 0.5493651343645845, 59: 0.4937984226857489, 60: 0.531137675746978}}
{'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-20 06:00:00'), 2: Timestamp('2020-09-20 12:00:00'), 3: Timestamp('2020-09-20 18:00:00'), 4: Timestamp('2020-09-21 00:00:00'), 5: Timestamp('2020-09-21 06:00:00'), 6: Timestamp('2020-09-21 12:00:00'), 7: Timestamp('2020-09-21 18:00:00'), 8: Timestamp('2020-09-22 00:00:00'), 9: Timestamp('2020-09-22 06:00:00'), 10: Timestamp('2020-09-22 12:00:00'), 11: Timestamp('2020-09-22 18:00:00'), 12: Timestamp('2020-09-23 00:00:00'), 13: Timestamp('2020-09-23 06:00:00'), 14: Timestamp('2020-09-23 12:00:00'), 15: Timestamp('2020-09-23 18:00:00'), 16: Timestamp('2020-09-24 00:00:00'), 17: Timestamp('2020-09-24 06:00:00'), 18: Timestamp('2020-09-24 12:00:00'), 19: Timestamp('2020-09-24 18:00:00'), 20: Timestamp('2020-09-25 00:00:00'), 21: Timestamp('2020-09-25 06:00:00'), 22: Timestamp('2020-09-25 12:00:00'), 23: Timestamp('2020-09-25 18:00:00'), 24: Timestamp('2020-09-26 00:00:00'), 25: Timestamp('2020-09-26 06:00:00'), 26: Timestamp('2020-09-26 12:00:00'), 27: Timestamp('2020-09-26 18:00:00'), 28: Timestamp('2020-09-27 00:00:00'), 29: Timestamp('2020-09-27 06:00:00'), 30: Timestamp('2020-09-27 12:00:00'), 31: Timestamp('2020-09-27 18:00:00'), 32: Timestamp('2020-09-28 00:00:00'), 33: Timestamp('2020-09-28 06:00:00'), 34: Timestamp('2020-09-28 12:00:00'), 35: Timestamp('2020-09-28 18:00:00'), 36: Timestamp('2020-09-29 00:00:00'), 37: Timestamp('2020-09-29 06:00:00'), 38: Timestamp('2020-09-29 12:00:00'), 39: Timestamp('2020-09-29 18:00:00'), 40: Timestamp('2020-09-30 00:00:00'), 41: Timestamp('2020-09-30 06:00:00'), 42: Timestamp('2020-09-30 12:00:00'), 43: Timestamp('2020-09-30 18:00:00'), 44: Timestamp('2020-10-01 00:00:00'), 45: Timestamp('2020-10-01 06:00:00'), 46: Timestamp('2020-10-01 12:00:00'), 47: Timestamp('2020-10-01 18:00:00'), 48: Timestamp('2020-10-02 00:00:00'), 49: Timestamp('2020-10-02 06:00:00'), 50: Timestamp('2020-10-02 12:00:00'), 51: Timestamp('2020-10-02 18:00:00'), 52: Timestamp('2020-10-03 00:00:00'), 53: Timestamp('2020-10-03 06:00:00'), 54: Timestamp('2020-10-03 12:00:00'), 55: Timestamp('2020-10-03 18:00:00'), 56: Timestamp('2020-10-04 00:00:00'), 57: Timestamp('2020-10-04 06:00:00'), 58: Timestamp('2020-10-04 12:00:00'), 59: Timestamp('2020-10-04 18:00:00'), 60: Timestamp('2020-10-05 00:00:00')}, '2m_temp_prod': {0: 299.4681144428137, 1: 294.4593329079582, 2: 293.54097959722486, 3: 301.26850218370805, 4: 300.4714986353434, 5: 295.6384695410705, 6: 294.2218375466852, 7: 301.7426496375417, 8: 300.4512511041961, 9: 295.3463775610583, 10: 294.00147574962756, 11: 302.04475406462933, 12: 300.7236658622478, 13: 295.24334771914255, 14: 293.7074020631231, 15: 301.7624504225804, 16: 300.4964931687989, 17: 294.75437504400884, 18: 293.1177542350017, 19: 301.0425274988938, 20: 299.46808452778663, 21: 293.52076913001173, 22: 291.3670613175431, 23: 299.3793965992101, 24: 297.7263093286383, 25: 291.7095202331552, 26: 289.6578323905783, 27: 298.15977187729777, 28: 296.9884342085861, 29: 291.43100183368114, 30: 289.77806100941024, 31: 299.00450242361666, 32: 298.15618404166, 33: 292.73800154126627, 34: 291.07457059787265, 35: 300.5683567053199, 36: 299.3708029435806, 37: 293.67890398828234, 38: 291.954942552734, 39: 301.1051505527471, 40: 299.7999782544342, 41: 294.0840368998602, 42: 292.31118300204673, 43: 301.3976538328202, 44: 300.07823191309984, 45: 294.45023381986016, 46: 292.62675527729584, 47: 301.7900197148812, 48: 300.5590082986463, 49: 294.9896801203776, 50: 293.1241761449157, 51: 302.36329836985607, 52: 300.97122596719737, 53: 295.59237808816266, 54: 293.67785157848175, 55: 302.64353699591527, 56: 301.1035750112269, 57: 295.9278212054364, 58: 294.0324357819224, 59: 302.4832018963981, 60: 300.8427400317463}, '2m_temp_area': {0: 299.4903718737801, 1: 294.2924835295078, 2: 293.30135473218274, 3: 301.3528640298525, 4: 300.5939881510472, 5: 295.70744811622785, 6: 294.2521907610824, 7: 301.7100774359669, 8: 300.44506163325167, 9: 295.238423311095, 10: 293.8509583022139, 11: 301.6235104014979, 12: 300.38743669809435, 13: 294.8808530776623, 14: 293.33325543225476, 15: 301.4149251854487, 16: 300.1796642776425, 17: 294.39239805130165, 18: 292.66981534530925, 19: 300.5419360845211, 20: 299.0580229759339, 21: 293.0690025289753, 22: 290.9169097601789, 23: 298.92199569749033, 24: 297.4673382419046, 25: 291.4599993026732, 26: 289.452388873785, 27: 297.98953222540143, 28: 296.98633186869347, 29: 291.4589865652578, 30: 289.8288914753008, 31: 298.94272407170354, 32: 298.23250648648224, 33: 292.83814534455996, 34: 291.11886718509857, 35: 300.40881750455577, 36: 299.31958687273186, 37: 293.607006890439, 38: 291.81444341023143, 39: 300.8265637430714, 40: 299.6454967052681, 41: 293.9106555122605, 42: 292.1023114379392, 43: 301.12502226064896, 44: 299.91897396641514, 45: 294.27870082533354, 46: 292.4308511036389, 47: 301.51583391071864, 48: 300.39429493794523, 49: 294.825486042682, 50: 292.93778771753085, 51: 302.0071005199438, 52: 300.74239613744925, 53: 295.38249105817647, 54: 293.45710875169135, 55: 302.25559951138456, 56: 300.8353769061142, 57: 295.6525398583873, 58: 293.7632451527435, 59: 302.0551372494585, 60: 300.54910101224283}, 'total_precip_prod': {0: 0.0, 1: 0.4344171852327147, 2: 0.4351379346608463, 3: 0.9091314020100694, 4: 0.7838464939768977, 5: 1.0303630570555136, 6: 1.168093427310163, 7: 0.8635649194545677, 8: 1.180842617204555, 9: 1.0926651254176625, 10: 0.8283334033945278, 11: 0.8444548557416743, 12: 1.3230640130302405, 13: 1.2194759096975982, 14: 0.7328129706460099, 15: 0.47450659159057845, 16: 0.5808363103089833, 17: 0.28338951318682726, 18: 0.39698079867625957, 19: 0.37495920568614616, 20: 0.33256622409109604, 21: 0.09931783596352596, 22: 0.1293731106563246, 23: 0.14798406577292791, 24: 0.18096669978617885, 25: 0.05295233242627148, 26: 0.11851136022355316, 27: 0.12519627617895362, 28: 0.09146508542790638, 29: 0.04829302677559146, 30: 0.11041590211762027, 31: 0.14573868900912046, 32: 0.18215252985155908, 33: 0.18280908457277276, 34: 0.2248243307367063, 35: 0.17947363978224146, 36: 0.2924242956937053, 37: 0.2586747544378083, 38: 0.33937087683999867, 39: 0.2928781027298378, 40: 0.3935333755687144, 41: 0.2365752557775799, 42: 0.3215975487263272, 43: 0.32446922789494864, 44: 0.40520923133523234, 45: 0.18850232039108583, 46: 0.3206818541123286, 47: 0.2592275400999963, 48: 0.2610206474998234, 49: 0.0825337926678261, 50: 0.19092392007472064, 51: 0.2515463341682229, 52: 0.32613213524316664, 53: 0.23563493853109554, 54: 0.4110033936434478, 55: 0.38235885945226183, 56: 0.42730548177205857, 57: 0.2815641222074818, 58: 0.5961723489376685, 59: 0.5535344292974106, 60: 0.590918096887046}, 'total_precip_area': {0: 0.0, 1: 0.3874422960619588, 2: 0.3534671039565543, 3: 0.7409486316169753, 4: 0.6940791707728421, 5: 1.050536962899086, 6: 1.1507307395821944, 7: 0.8040717430552817, 8: 1.2714251971087065, 9: 1.238737113112408, 10: 0.874670190928147, 11: 1.0056286133748165, 12: 1.4698900412759783, 13: 1.003917146674298, 14: 0.6760869472842964, 15: 0.46827391738334945, 16: 0.6192899499044445, 17: 0.30060294065641396, 18: 0.41819106385838506, 19: 0.42650150247172797, 20: 0.37798023230687594, 21: 0.13500750520245205, 22: 0.14298402753104766, 23: 0.15948345822813867, 24: 0.18379226168252366, 25: 0.06000665823151941, 26: 0.1208072573649105, 27: 0.1350174494403403, 28: 0.11033956479303804, 29: 0.06970661157888385, 30: 0.16430003817188624, 31: 0.20396331622388164, 32: 0.2434592812259675, 33: 0.2349487648431431, 34: 0.2746628172448139, 35: 0.2223445586696201, 36: 0.32000417926146, 37: 0.2856880861377167, 38: 0.3563173295637319, 39: 0.2961985136805571, 40: 0.39572744360892087, 41: 0.25261863325235423, 42: 0.3480723202390621, 43: 0.33450860690381784, 44: 0.40810079238884994, 45: 0.2246481215656477, 46: 0.322536138199169, 47: 0.26302935652500986, 48: 0.26877015748360655, 49: 0.10435240067851569, 50: 0.23626983714582017, 51: 0.2921901873852093, 52: 0.3573174778311772, 53: 0.2690948499009291, 54: 0.43485595266861593, 55: 0.3857033635552736, 56: 0.45008050524046406, 57: 0.31559742112580763, 58: 0.5897464914238096, 59: 0.5591084829706243, 60: 0.6031174118554716}}
As you can see, the dataframes are related to each other. The first dataframe contains 6-hourly data from a forecast model that goes out 15 days for 4 different variables. The second dataframe contains 24-hourly data that describes the change in the value of the specific variable in df_vals from 24 hours ago (the delta). As such, I want to plot a line graph for the actual values on the y1 axis, and a bar graph to show the change in 24 hours on the y2 axis.
I have been able to plot the values from df_vals as a simple line graph and make it interactive so the user can switch between between different dataframes, but also different variables within the dataframe. Code for that here:
app = JupyterDash(__name__)
cols=df_vals['corn'].columns[1:]
app.layout = html.Div([
html.Div([
html.Div([
dcc.Dropdown(
id='variables',
options=[{'label': i, 'value': i} for i in cols],
value='2m_temp_prod'
)
]),
html.Div([
dcc.Dropdown(
id='crop_dropdown',
options=[{'label': i, 'value': i} for i in df_vals.keys()],
value='corn'
)
]),
dcc.Graph(id='plot')])
])
#app.callback(
Output('crop-dropdown', 'options'),
[Input('variables', 'value')])
def update_crop_dropdown(crop):
return [{'label': i, 'value': i} for i in df_vals[crop]]
#app.callback(
Output('plot', 'figure'),
[Input('crop_dropdown', 'value'),
Input('variables', 'value')])
def update_graph(crops, variable_name):
if crops:
return go.Figure(data=go.Scatter(x=df_vals[crops]['time'], y=df_vals[crops][variable_name], mode='lines'))
else:
return go.Figure(data=[])
app.run_server(mode='inline')
I want the similar column names in df_vals and df_deltas to be plotted together. For example, the column name '2m_temp_prod' in df_vals and '2m_temp_24hdelta_prod' in df_deltas would be plotted together. The same idea applies for the other 3 columns.
I am confused how I let the app know that I want to update both the first and second y-axis, but only provide one dropdown to do so.
An example plot is provided where I was able to accomplish this task, but as a stand alone, non-interactive plot. The purpose of the example is to make sure what I am trying to achieve is clear.
I've prepared a setup using Dash that should take all your considerations into account.
You can select crop type ['corn', 'soybeans', 'winterwheat', 'springwheat']
You can select which columns to display on the primary y-axis for each croptype in df_vals.
And you can select which columns to display on the secondary y-axis for each croptype in df_deltas.
Since the datasets in df_vals and df_deltas are displayed on the primary and secondary y-axis respectively, they are not part of the menu selections. The buttons provided should do be sufficient if I'm understanding your question correctly.
Plot 1: Crop=Corn, df_vals=2m_temp_prod, df_deltas=2m_prod_24hdelta_prod
Plot 2: Crop=Soybeans, df_vals=total_precip_prod, df_deltas=total_precip_24hdelta_area
Complete code:
from jupyter_dash import JupyterDash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State, ClientsideFunction
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import numpy as np
from plotly.subplots import make_subplots
from pandas import Timestamp
# data
df_vals = {'corn': pd.DataFrame({'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-20 06:00:00'), 2: Timestamp('2020-09-20 12:00:00'), 3: Timestamp('2020-09-20 18:00:00'), 4: Timestamp('2020-09-21 00:00:00'), 5: Timestamp('2020-09-21 06:00:00'), 6: Timestamp('2020-09-21 12:00:00'), 7: Timestamp('2020-09-21 18:00:00'), 8: Timestamp('2020-09-22 00:00:00'), 9: Timestamp('2020-09-22 06:00:00'), 10: Timestamp('2020-09-22 12:00:00'), 11: Timestamp('2020-09-22 18:00:00'), 12: Timestamp('2020-09-23 00:00:00'), 13: Timestamp('2020-09-23 06:00:00'), 14: Timestamp('2020-09-23 12:00:00'), 15: Timestamp('2020-09-23 18:00:00'), 16: Timestamp('2020-09-24 00:00:00'), 17: Timestamp('2020-09-24 06:00:00'), 18: Timestamp('2020-09-24 12:00:00'), 19: Timestamp('2020-09-24 18:00:00'), 20: Timestamp('2020-09-25 00:00:00'), 21: Timestamp('2020-09-25 06:00:00'), 22: Timestamp('2020-09-25 12:00:00'), 23: Timestamp('2020-09-25 18:00:00'), 24: Timestamp('2020-09-26 00:00:00'), 25: Timestamp('2020-09-26 06:00:00'), 26: Timestamp('2020-09-26 12:00:00'), 27: Timestamp('2020-09-26 18:00:00'), 28: Timestamp('2020-09-27 00:00:00'), 29: Timestamp('2020-09-27 06:00:00'), 30: Timestamp('2020-09-27 12:00:00'), 31: Timestamp('2020-09-27 18:00:00'), 32: Timestamp('2020-09-28 00:00:00'), 33: Timestamp('2020-09-28 06:00:00'), 34: Timestamp('2020-09-28 12:00:00'), 35: Timestamp('2020-09-28 18:00:00'), 36: Timestamp('2020-09-29 00:00:00'), 37: Timestamp('2020-09-29 06:00:00'), 38: Timestamp('2020-09-29 12:00:00'), 39: Timestamp('2020-09-29 18:00:00'), 40: Timestamp('2020-09-30 00:00:00'), 41: Timestamp('2020-09-30 06:00:00'), 42: Timestamp('2020-09-30 12:00:00'), 43: Timestamp('2020-09-30 18:00:00'), 44: Timestamp('2020-10-01 00:00:00'), 45: Timestamp('2020-10-01 06:00:00'), 46: Timestamp('2020-10-01 12:00:00'), 47: Timestamp('2020-10-01 18:00:00'), 48: Timestamp('2020-10-02 00:00:00'), 49: Timestamp('2020-10-02 06:00:00'), 50: Timestamp('2020-10-02 12:00:00'), 51: Timestamp('2020-10-02 18:00:00'), 52: Timestamp('2020-10-03 00:00:00'), 53: Timestamp('2020-10-03 06:00:00'), 54: Timestamp('2020-10-03 12:00:00'), 55: Timestamp('2020-10-03 18:00:00'), 56: Timestamp('2020-10-04 00:00:00'), 57: Timestamp('2020-10-04 06:00:00'), 58: Timestamp('2020-10-04 12:00:00'), 59: Timestamp('2020-10-04 18:00:00'), 60: Timestamp('2020-10-05 00:00:00')}, '2m_temp_prod': {0: 299.346777266481, 1: 294.0395117035824, 2: 292.9592738522704, 3: 301.3180464757325, 4: 300.62356652087135, 5: 295.3372490145483, 6: 293.70255086586366, 7: 301.74835531223954, 8: 300.63094530701716, 9: 295.19553201608596, 10: 293.61613871139605, 11: 302.1631229776387, 12: 300.9153730135594, 13: 295.15968865817507, 14: 293.4150837111033, 15: 301.41874976967574, 16: 300.2591302298784, 17: 294.35648855874496, 18: 292.60893943975975, 19: 300.69793228145136, 20: 299.21051997362474, 21: 293.03793188187217, 22: 290.7864320360987, 23: 298.83351270175194, 24: 297.3528693941268, 25: 291.19369512544074, 26: 289.09521928196455, 27: 297.6441935083638, 28: 296.7296754953959, 29: 290.9897312443865, 30: 289.32126319033677, 31: 298.7574828448876, 32: 298.12901959834915, 33: 292.5899489699376, 34: 290.89859256270717, 35: 300.43330551865887, 36: 299.4213926560918, 37: 293.6473005538043, 38: 291.78953606425546, 39: 300.96031965551913, 40: 299.8616920790521, 41: 293.9476866306047, 42: 292.00448821963647, 43: 301.2204786022793, 44: 300.1545728526989, 45: 294.30968496479613, 46: 292.3264718663577, 47: 301.6422264431679, 48: 300.6382119018213, 49: 294.9066383821488, 50: 292.9206232319892, 51: 302.28532470110673, 52: 301.118337633183, 53: 295.580361365072, 54: 293.5071232611944, 55: 302.4993713158521, 56: 301.1771411161832, 57: 295.87429820309063, 58: 293.8387870006977, 59: 302.3844741742686, 60: 300.92076629492163}, '2m_temp_area': {0: 299.79923425166567, 1: 294.4433522483179, 2: 293.1829305163771, 3: 301.76751592578194, 4: 300.97964970416314, 5: 295.58816311209137, 6: 293.944118250348, 7: 302.20448177813586, 8: 301.0782745090335, 9: 295.36833103932497, 10: 293.7448705435944, 11: 302.2414068531493, 12: 300.97154909133104, 13: 295.09171791304016, 14: 293.29872586829305, 15: 301.63398450993316, 16: 300.39729350367077, 17: 294.4765532352668, 18: 292.6348308697987, 19: 300.7196467769189, 20: 299.2413397435659, 21: 293.1571305856655, 22: 290.9298399188299, 23: 299.0361571649767, 24: 297.6784967259681, 25: 291.6225850820778, 26: 289.5307387179231, 27: 298.1675193109706, 28: 297.2851193736129, 29: 291.6047803054954, 30: 289.8725165929944, 31: 299.2259541567033, 32: 298.5645974740215, 33: 292.9844928941141, 34: 291.16692080415885, 35: 300.6640689360243, 36: 299.63105315816887, 37: 293.7973759485704, 38: 291.8748714049971, 39: 301.07558737962773, 40: 299.9769492884242, 41: 294.06556034682825, 42: 292.0989825175383, 43: 301.3224275326778, 44: 300.2429318269633, 45: 294.4016189433437, 46: 292.39193470959646, 47: 301.691478296914, 48: 300.693790365317, 49: 294.95729295702677, 50: 292.94815058578274, 51: 302.1922658603409, 52: 301.01878139937173, 53: 295.47413908911483, 54: 293.41960123543845, 55: 302.34370446075303, 56: 301.05227283650527, 57: 295.72013507339597, 58: 293.6867376233815, 59: 302.19133411599717, 60: 300.81799340051333}, 'total_precip_prod': {0: 0.0, 1: 0.19106968995229195, 2: 0.1557650112297922, 3: 0.42176822127339436, 4: 0.3635719686978164, 5: 0.624238127750141, 6: 0.7363658332723646, 7: 0.6637602529624484, 8: 0.8303668371501847, 9: 0.9645353650727154, 10: 0.9080621631493283, 11: 0.7407109615632305, 12: 1.2188155467167008, 13: 1.4934816133864144, 14: 0.8673540204216558, 15: 0.4536446670226782, 16: 0.5838893851141779, 17: 0.28997017910749373, 18: 0.396575809101194, 19: 0.3017425722928852, 20: 0.2600037974259506, 21: 0.10090977019496428, 22: 0.1120663639424084, 23: 0.11820662603244433, 24: 0.11351422163952127, 25: 0.0354462928350286, 26: 0.08973231687769569, 27: 0.11707786940722151, 28: 0.07097838855834729, 29: 0.03411315769121203, 30: 0.09051350215127027, 31: 0.11314915610119855, 32: 0.14753233086329737, 33: 0.1845242398275337, 34: 0.2518174918229658, 35: 0.17011312187047897, 36: 0.2749232044764252, 37: 0.2972017724997405, 38: 0.3552475267861772, 39: 0.27943871692889416, 40: 0.31981605728486306, 41: 0.19735958986038185, 42: 0.2806487307465678, 43: 0.2830918175327961, 44: 0.3288561686915008, 45: 0.1744303376099874, 46: 0.30609645936303326, 47: 0.21925050665230758, 48: 0.20281755796768022, 49: 0.06620804878284778, 50: 0.17684099550656973, 51: 0.19853145136367492, 52: 0.2563854573673008, 53: 0.24201876323456878, 54: 0.41939251801295807, 55: 0.36402178359658277, 56: 0.37120895070913373, 57: 0.281792653746079, 58: 0.5868870658107626, 59: 0.4927117680726645, 60: 0.5223743530274055}, 'total_precip_area': {0: 0.0, 1: 0.2869521154242563, 2: 0.21660564402622137, 3: 0.4856913604264373, 4: 0.5011640941544891, 5: 0.7562519498474788, 6: 0.7839821183163472, 7: 0.5862595162666312, 8: 0.8974715199444484, 9: 0.9610750641626696, 10: 0.7601911282379429, 11: 0.793906823631679, 12: 1.2383530336279156, 13: 1.0049543280590305, 14: 0.6820852351772055, 15: 0.442434189821785, 16: 0.6589929874909368, 17: 0.32723035127408134, 18: 0.4144798865599254, 19: 0.368782410513661, 20: 0.36137157927969976, 21: 0.1635789497829729, 22: 0.16409778482825316, 23: 0.16768421904602382, 24: 0.1808376986943956, 25: 0.058153150056705245, 26: 0.1269072928484502, 27: 0.14562713451681256, 28: 0.11216762073388148, 29: 0.062161294677683845, 30: 0.13994272590442386, 31: 0.1662560753829063, 32: 0.20624170840852787, 33: 0.216927525300605, 34: 0.26804054777036235, 35: 0.20587583527311556, 36: 0.297848309035157, 37: 0.2836083045675833, 38: 0.33686407205543173, 39: 0.276288892940258, 40: 0.3569925386418611, 41: 0.2258142673918131, 42: 0.30458249604018844, 43: 0.2882872466330577, 44: 0.36861110970625127, 45: 0.1945528585156628, 46: 0.2996099093542968, 47: 0.2370841370242934, 48: 0.24429531409451738, 49: 0.09534765734716107, 50: 0.19399822393477686, 51: 0.24311804406545334, 52: 0.3062432174815857, 53: 0.27031885272433986, 54: 0.40763842665734645, 55: 0.3546261915245615, 56: 0.4085152708749088, 57: 0.30056439476727764, 58: 0.5493651343645845, 59: 0.4937984226857489, 60: 0.531137675746978}}),
'soybeans':pd.DataFrame({'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-20 06:00:00'), 2: Timestamp('2020-09-20 12:00:00'), 3: Timestamp('2020-09-20 18:00:00'), 4: Timestamp('2020-09-21 00:00:00'), 5: Timestamp('2020-09-21 06:00:00'), 6: Timestamp('2020-09-21 12:00:00'), 7: Timestamp('2020-09-21 18:00:00'), 8: Timestamp('2020-09-22 00:00:00'), 9: Timestamp('2020-09-22 06:00:00'), 10: Timestamp('2020-09-22 12:00:00'), 11: Timestamp('2020-09-22 18:00:00'), 12: Timestamp('2020-09-23 00:00:00'), 13: Timestamp('2020-09-23 06:00:00'), 14: Timestamp('2020-09-23 12:00:00'), 15: Timestamp('2020-09-23 18:00:00'), 16: Timestamp('2020-09-24 00:00:00'), 17: Timestamp('2020-09-24 06:00:00'), 18: Timestamp('2020-09-24 12:00:00'), 19: Timestamp('2020-09-24 18:00:00'), 20: Timestamp('2020-09-25 00:00:00'), 21: Timestamp('2020-09-25 06:00:00'), 22: Timestamp('2020-09-25 12:00:00'), 23: Timestamp('2020-09-25 18:00:00'), 24: Timestamp('2020-09-26 00:00:00'), 25: Timestamp('2020-09-26 06:00:00'), 26: Timestamp('2020-09-26 12:00:00'), 27: Timestamp('2020-09-26 18:00:00'), 28: Timestamp('2020-09-27 00:00:00'), 29: Timestamp('2020-09-27 06:00:00'), 30: Timestamp('2020-09-27 12:00:00'), 31: Timestamp('2020-09-27 18:00:00'), 32: Timestamp('2020-09-28 00:00:00'), 33: Timestamp('2020-09-28 06:00:00'), 34: Timestamp('2020-09-28 12:00:00'), 35: Timestamp('2020-09-28 18:00:00'), 36: Timestamp('2020-09-29 00:00:00'), 37: Timestamp('2020-09-29 06:00:00'), 38: Timestamp('2020-09-29 12:00:00'), 39: Timestamp('2020-09-29 18:00:00'), 40: Timestamp('2020-09-30 00:00:00'), 41: Timestamp('2020-09-30 06:00:00'), 42: Timestamp('2020-09-30 12:00:00'), 43: Timestamp('2020-09-30 18:00:00'), 44: Timestamp('2020-10-01 00:00:00'), 45: Timestamp('2020-10-01 06:00:00'), 46: Timestamp('2020-10-01 12:00:00'), 47: Timestamp('2020-10-01 18:00:00'), 48: Timestamp('2020-10-02 00:00:00'), 49: Timestamp('2020-10-02 06:00:00'), 50: Timestamp('2020-10-02 12:00:00'), 51: Timestamp('2020-10-02 18:00:00'), 52: Timestamp('2020-10-03 00:00:00'), 53: Timestamp('2020-10-03 06:00:00'), 54: Timestamp('2020-10-03 12:00:00'), 55: Timestamp('2020-10-03 18:00:00'), 56: Timestamp('2020-10-04 00:00:00'), 57: Timestamp('2020-10-04 06:00:00'), 58: Timestamp('2020-10-04 12:00:00'), 59: Timestamp('2020-10-04 18:00:00'), 60: Timestamp('2020-10-05 00:00:00')}, '2m_temp_prod': {0: 299.4681144428137, 1: 294.4593329079582, 2: 293.54097959722486, 3: 301.26850218370805, 4: 300.4714986353434, 5: 295.6384695410705, 6: 294.2218375466852, 7: 301.7426496375417, 8: 300.4512511041961, 9: 295.3463775610583, 10: 294.00147574962756, 11: 302.04475406462933, 12: 300.7236658622478, 13: 295.24334771914255, 14: 293.7074020631231, 15: 301.7624504225804, 16: 300.4964931687989, 17: 294.75437504400884, 18: 293.1177542350017, 19: 301.0425274988938, 20: 299.46808452778663, 21: 293.52076913001173, 22: 291.3670613175431, 23: 299.3793965992101, 24: 297.7263093286383, 25: 291.7095202331552, 26: 289.6578323905783, 27: 298.15977187729777, 28: 296.9884342085861, 29: 291.43100183368114, 30: 289.77806100941024, 31: 299.00450242361666, 32: 298.15618404166, 33: 292.73800154126627, 34: 291.07457059787265, 35: 300.5683567053199, 36: 299.3708029435806, 37: 293.67890398828234, 38: 291.954942552734, 39: 301.1051505527471, 40: 299.7999782544342, 41: 294.0840368998602, 42: 292.31118300204673, 43: 301.3976538328202, 44: 300.07823191309984, 45: 294.45023381986016, 46: 292.62675527729584, 47: 301.7900197148812, 48: 300.5590082986463, 49: 294.9896801203776, 50: 293.1241761449157, 51: 302.36329836985607, 52: 300.97122596719737, 53: 295.59237808816266, 54: 293.67785157848175, 55: 302.64353699591527, 56: 301.1035750112269, 57: 295.9278212054364, 58: 294.0324357819224, 59: 302.4832018963981, 60: 300.8427400317463}, '2m_temp_area': {0: 299.4903718737801, 1: 294.2924835295078, 2: 293.30135473218274, 3: 301.3528640298525, 4: 300.5939881510472, 5: 295.70744811622785, 6: 294.2521907610824, 7: 301.7100774359669, 8: 300.44506163325167, 9: 295.238423311095, 10: 293.8509583022139, 11: 301.6235104014979, 12: 300.38743669809435, 13: 294.8808530776623, 14: 293.33325543225476, 15: 301.4149251854487, 16: 300.1796642776425, 17: 294.39239805130165, 18: 292.66981534530925, 19: 300.5419360845211, 20: 299.0580229759339, 21: 293.0690025289753, 22: 290.9169097601789, 23: 298.92199569749033, 24: 297.4673382419046, 25: 291.4599993026732, 26: 289.452388873785, 27: 297.98953222540143, 28: 296.98633186869347, 29: 291.4589865652578, 30: 289.8288914753008, 31: 298.94272407170354, 32: 298.23250648648224, 33: 292.83814534455996, 34: 291.11886718509857, 35: 300.40881750455577, 36: 299.31958687273186, 37: 293.607006890439, 38: 291.81444341023143, 39: 300.8265637430714, 40: 299.6454967052681, 41: 293.9106555122605, 42: 292.1023114379392, 43: 301.12502226064896, 44: 299.91897396641514, 45: 294.27870082533354, 46: 292.4308511036389, 47: 301.51583391071864, 48: 300.39429493794523, 49: 294.825486042682, 50: 292.93778771753085, 51: 302.0071005199438, 52: 300.74239613744925, 53: 295.38249105817647, 54: 293.45710875169135, 55: 302.25559951138456, 56: 300.8353769061142, 57: 295.6525398583873, 58: 293.7632451527435, 59: 302.0551372494585, 60: 300.54910101224283}, 'total_precip_prod': {0: 0.0, 1: 0.4344171852327147, 2: 0.4351379346608463, 3: 0.9091314020100694, 4: 0.7838464939768977, 5: 1.0303630570555136, 6: 1.168093427310163, 7: 0.8635649194545677, 8: 1.180842617204555, 9: 1.0926651254176625, 10: 0.8283334033945278, 11: 0.8444548557416743, 12: 1.3230640130302405, 13: 1.2194759096975982, 14: 0.7328129706460099, 15: 0.47450659159057845, 16: 0.5808363103089833, 17: 0.28338951318682726, 18: 0.39698079867625957, 19: 0.37495920568614616, 20: 0.33256622409109604, 21: 0.09931783596352596, 22: 0.1293731106563246, 23: 0.14798406577292791, 24: 0.18096669978617885, 25: 0.05295233242627148, 26: 0.11851136022355316, 27: 0.12519627617895362, 28: 0.09146508542790638, 29: 0.04829302677559146, 30: 0.11041590211762027, 31: 0.14573868900912046, 32: 0.18215252985155908, 33: 0.18280908457277276, 34: 0.2248243307367063, 35: 0.17947363978224146, 36: 0.2924242956937053, 37: 0.2586747544378083, 38: 0.33937087683999867, 39: 0.2928781027298378, 40: 0.3935333755687144, 41: 0.2365752557775799, 42: 0.3215975487263272, 43: 0.32446922789494864, 44: 0.40520923133523234, 45: 0.18850232039108583, 46: 0.3206818541123286, 47: 0.2592275400999963, 48: 0.2610206474998234, 49: 0.0825337926678261, 50: 0.19092392007472064, 51: 0.2515463341682229, 52: 0.32613213524316664, 53: 0.23563493853109554, 54: 0.4110033936434478, 55: 0.38235885945226183, 56: 0.42730548177205857, 57: 0.2815641222074818, 58: 0.5961723489376685, 59: 0.5535344292974106, 60: 0.590918096887046}, 'total_precip_area': {0: 0.0, 1: 0.3874422960619588, 2: 0.3534671039565543, 3: 0.7409486316169753, 4: 0.6940791707728421, 5: 1.050536962899086, 6: 1.1507307395821944, 7: 0.8040717430552817, 8: 1.2714251971087065, 9: 1.238737113112408, 10: 0.874670190928147, 11: 1.0056286133748165, 12: 1.4698900412759783, 13: 1.003917146674298, 14: 0.6760869472842964, 15: 0.46827391738334945, 16: 0.6192899499044445, 17: 0.30060294065641396, 18: 0.41819106385838506, 19: 0.42650150247172797, 20: 0.37798023230687594, 21: 0.13500750520245205, 22: 0.14298402753104766, 23: 0.15948345822813867, 24: 0.18379226168252366, 25: 0.06000665823151941, 26: 0.1208072573649105, 27: 0.1350174494403403, 28: 0.11033956479303804, 29: 0.06970661157888385, 30: 0.16430003817188624, 31: 0.20396331622388164, 32: 0.2434592812259675, 33: 0.2349487648431431, 34: 0.2746628172448139, 35: 0.2223445586696201, 36: 0.32000417926146, 37: 0.2856880861377167, 38: 0.3563173295637319, 39: 0.2961985136805571, 40: 0.39572744360892087, 41: 0.25261863325235423, 42: 0.3480723202390621, 43: 0.33450860690381784, 44: 0.40810079238884994, 45: 0.2246481215656477, 46: 0.322536138199169, 47: 0.26302935652500986, 48: 0.26877015748360655, 49: 0.10435240067851569, 50: 0.23626983714582017, 51: 0.2921901873852093, 52: 0.3573174778311772, 53: 0.2690948499009291, 54: 0.43485595266861593, 55: 0.3857033635552736, 56: 0.45008050524046406, 57: 0.31559742112580763, 58: 0.5897464914238096, 59: 0.5591084829706243, 60: 0.6031174118554716}})}
df_deltas = {'corn': pd.DataFrame({'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-21 00:00:00'), 2: Timestamp('2020-09-22 00:00:00'), 3: Timestamp('2020-09-23 00:00:00'), 4: Timestamp('2020-09-24 00:00:00'), 5: Timestamp('2020-09-25 00:00:00'), 6: Timestamp('2020-09-26 00:00:00'), 7: Timestamp('2020-09-27 00:00:00'), 8: Timestamp('2020-09-28 00:00:00'), 9: Timestamp('2020-09-29 00:00:00'), 10: Timestamp('2020-09-30 00:00:00'), 11: Timestamp('2020-10-01 00:00:00'), 12: Timestamp('2020-10-02 00:00:00'), 13: Timestamp('2020-10-03 00:00:00'), 14: Timestamp('2020-10-04 00:00:00'), 15: Timestamp('2020-10-05 00:00:00')}, '2m_temp_24hdelta_prod': {0: -0.33056551535638423, 1: -0.06352654836543402, 2: -0.276225357129493, 3: -0.7788107233764435, 4: -0.12182345812042986, 5: 0.4844870528180379, 6: -0.7795401737865336, 7: -1.3736563255451468, 8: -0.7925949910485673, 9: -0.6084065411465024, 10: -0.6532739602739552, 11: -0.5334182358612463, 12: -0.3214601096392593, 13: 0.005672046711691303, 14: 0.294874775721931, 15: 0.0}, '2m_temp_24hdelta_area': {0: -0.2942234811255382, 1: -0.06695257736951654, 2: -0.2382484006633631, 3: -0.747444491858053, 4: -0.008792915536150941, 5: 0.25843822574146474, 6: -0.8653840134962728, 7: -1.3306357244341183, 8: -0.77807373911064, 9: -0.6101878063800394, 10: -0.6602593986352374, 11: -0.5377113682438022, 12: -0.3489377042704134, 13: -0.12997682663355925, 14: 0.08031697715852158, 15: 0.0}, 'total_precip_24hdelta_prod': {0: -1.4417379991236094, 1: -3.24276961794111, 2: -1.9549294932106442, 3: 1.0805492310759035, 4: -2.8572102912370547, 5: -0.6036102993252254, 6: 0.068152851219848, 7: -0.37760433118519804, 8: -0.2182212103223477, 9: 0.14385291749053375, 10: -0.09611101762074367, 11: -0.44170367466228744, 12: -0.9926136091953488, 13: -0.26638156415402015, 14: -0.0435076228174961, 15: 0.0}, 'total_precip_24hdelta_area': {0: -0.8969484573159082, 1: -2.002193332285897, 2: -1.3265684841453602, 3: 0.5232970017014504, 4: -1.9744318826572878, 5: -0.4756557183821801, 6: 0.09401319045911638, 7: -0.2480262049680989, 8: -0.16164720991353132, 9: 0.12918646107950632, 10: -0.025385234499880355, 11: -0.37094005589542123, 12: -0.7621485373750772, 13: -0.21974376949919702, 14: -0.06387744429696394, 15: 0.0}}),
'soybeans':pd.DataFrame({'time': {0: Timestamp('2020-09-20 00:00:00'), 1: Timestamp('2020-09-21 00:00:00'), 2: Timestamp('2020-09-22 00:00:00'), 3: Timestamp('2020-09-23 00:00:00'), 4: Timestamp('2020-09-24 00:00:00'), 5: Timestamp('2020-09-25 00:00:00'), 6: Timestamp('2020-09-26 00:00:00'), 7: Timestamp('2020-09-27 00:00:00'), 8: Timestamp('2020-09-28 00:00:00'), 9: Timestamp('2020-09-29 00:00:00'), 10: Timestamp('2020-09-30 00:00:00'), 11: Timestamp('2020-10-01 00:00:00'), 12: Timestamp('2020-10-02 00:00:00'), 13: Timestamp('2020-10-03 00:00:00'), 14: Timestamp('2020-10-04 00:00:00'), 15: Timestamp('2020-10-05 00:00:00')}, '2m_temp_24hdelta_prod': {0: -0.41072100441995785, 1: -0.11297222900273206, 2: -0.3134558546203517, 3: -0.7055797268403201, 4: -0.14038170579478787, 5: 0.2625117005223226, 6: -0.7101408224478941, 7: -1.2573241419225902, 8: -0.7906424533010389, 9: -0.661536032998284, 10: -0.6822789549363446, 11: -0.5744259308508103, 12: -0.4206210457410846, 13: -0.08431581171659296, 14: 0.2654961632050054, 15: 0.0}, '2m_temp_24hdelta_area': {0: -0.36772899690348704, 1: -0.05348366544356093, 2: -0.24183851104639115, 3: -0.6953305273210354, 4: -0.045424744173602496, 5: 0.19001500780368247, 6: -0.821935103347599, 7: -1.265563237441084, 8: -0.7328581189116925, 9: -0.6143048783236709, 10: -0.6633462127739507, 11: -0.5190203572096471, 12: -0.39498226425933547, 13: -0.10526773964830015, 14: 0.19258302497068705, 15: 0.0}, 'total_precip_24hdelta_prod': {0: -0.6776698356563055, 1: -1.7516299539550721, 2: -1.270815712012518, 3: 0.5996647217068156, 4: -2.2466045890287396, 5: -0.6706621597096377, 6: 0.06719919310410405, 7: -0.3572052717181586, 8: -0.2512178851633781, 9: 0.1313636195701381, 10: 0.08179245850142033, 11: -0.3036658888458674, 12: -0.8200237460316371, 13: -0.32927495598480583, 14: -0.08189579932441349, 15: 0.0}, 'total_precip_24hdelta_area': {0: -0.7530386453128719, 1: -1.7027556154743797, 2: -1.0907657669920294, 3: 0.429094034006764, 4: -1.9424324271143407, 5: -0.5370968484676638, 6: 0.044404490985521246, 7: -0.30794153270377544, 8: -0.2471378005907392, 9: 0.1212115468745879, 10: 0.07486462848670472, 11: -0.3507116185903665, 12: -0.7247205225779287, 13: -0.25431240691233936, 14: -0.06960793926681186, 15: 0.0}})}
# managed indexes
df_vals['corn'].set_index('time', inplace=True)
df_vals['soybeans'].set_index('time', inplace=True)
df_deltas['corn'].set_index('time', inplace=True)
df_deltas['soybeans'].set_index('time', inplace=True)
# Dash app setup
app = JupyterDash(external_stylesheets=[dbc.themes.SLATE])
# controls
controls = dbc.Card(
[ dbc.FormGroup(
[
dbc.Label("Crop"),
dcc.Dropdown(
id="Crop",
options=[
{"label": col, "value": col} for col in list(df_vals.keys())
],
value=list(df_vals.keys())[0],
clearable=False,
),
]
),
dbc.FormGroup(
[
dbc.Label("df_vals"),
dcc.Dropdown(
id="val_cols",
options=[
{"label": col, "value": col} for col in df_vals[list(df_vals.keys())[0]].columns
],
value=df_vals[list(df_vals.keys())[0]].columns[0],
clearable=False,
),
]
),
dbc.FormGroup(
[
dbc.Label("df_deltas"),
dcc.Dropdown(
id="delta_cols",
options=[
{"label": col, "value": col} for col in df_deltas[list(df_deltas.keys())[0]].columns
],
value=df_deltas[list(df_deltas.keys())[0]].columns[0],
clearable=False
),
]
),
],
body=True,
)
# Layout
app.layout = dbc.Container(
[
html.H1("Plotly Dash"),
html.Hr(),
dbc.Row([
dbc.Col([
dbc.Row([
dbc.Col(controls)
], align="start"),
dbc.Row([
dbc.Col([
html.Br(),
dbc.Row([
dbc.Col([html.Div(id = 'txt1')
])
]),
html.Br(),
dbc.Row([
dbc.Col([html.Div(id = 'txt2')])
])
])
])
],xs = 4)
,
dbc.Col([
dbc.Row([
dbc.Col([html.Div(id = 'plot_title')],)
]),
dbc.Row([
dbc.Col(dcc.Graph(id="crop-graph")),
#dbc.Col(dcc.Graph(id="cluster-graph"))
])
])
],),
],
fluid=True,
)
#app.callback(
Output("crop-graph", "figure"),
[ Input("Crop", "value"),
Input("val_cols", "value"),
Input("delta_cols", "value"),
#Input("cluster-count", "value"),
],
)
def crop_graph(Crop, val, delta):
# plotly figure setup
fig = make_subplots(specs=[[{"secondary_y": True}]])
# traces for df_vals
fig.add_trace(go.Scatter(name=val, x=df_vals[Crop].index, y=df_vals[Crop][val], mode = 'lines'), secondary_y=False,
)
# traces for df_deltas
fig.add_trace(go.Scatter(name=delta, x=df_deltas[Crop].index, y=df_deltas[Crop][delta], mode = 'lines'), secondary_y=True,
)
# aesthetics
fig.update_layout(template="plotly_dark", plot_bgcolor='#272B30', paper_bgcolor='#272B30')
fig.update_layout(margin= {'t':150, 'b':0, 'r': 0, 'l': 0, 'pad': 0})
fig.update_layout(hovermode = 'x')
fig.update_layout(showlegend=True, legend=dict(x=1,y=0.85))
fig.update_layout(title = dict(text = 'Crop: '+ Crop + ', Vals: ' + val + ', Deltas: '+delta))
return(fig)
app.run_server(mode='external', port = 8099)
Is there a way to visualize the results below?
29% of the results has accuracy >= 90%
59% of the results has accuracy >= 80%
88% of the results has accuracy >= 70%
98% of the results has accuracy >= 60%
2 entries with 59% and 57%
Below is the code with test result (accuracy) and rolling percentage
df1 = pd.DataFrame( {'Test Results': {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0, 5: 1.0, 6: 1.0, 7: 1.0, 8: 1.0, 9: 1.0, 10: 1.0, 11: 1.0, 12: 1.0, 13: 1.0, 14: 1.0, 15: 1.0, 16: 1.0, 17: 1.0, 18: 1.0, 19: 1.0, 20: 0.9452757159999999, 21: 0.9450125009999999, 22: 0.941873717, 23: 0.9336287990000001, 24: 0.932937845, 25: 0.928728552, 26: 0.9217334709999999, 27: 0.9212251640000001, 28: 0.903416839, 29: 0.900519655, 30: 0.8946950090000001, 31: 0.894315668, 32: 0.893705918, 33: 0.8911087870000001, 34: 0.88341769, 35: 0.875316697, 36: 0.873369453, 37: 0.8724485759999999, 38: 0.870855835, 39: 0.8682100159999999, 40: 0.866413987, 41: 0.866225758, 42: 0.86607366, 43: 0.861137576, 44: 0.8570423090000001, 45: 0.855989443, 46: 0.8363952240000001, 47: 0.835153771, 48: 0.831573322, 49: 0.8297349890000001, 50: 0.827174152, 51: 0.82533598, 52: 0.8244730259999999, 53: 0.8231749909999999, 54: 0.821542323, 55: 0.81994456, 56: 0.8193151340000001, 57: 0.817544275, 58: 0.8043684740000001, 59: 0.804280654, 60: 0.804033467, 61: 0.8024588559999999, 62: 0.799949648, 63: 0.7998811370000001, 64: 0.7993836879999999, 65: 0.7978083340000001, 66: 0.794987453, 67: 0.7942367459999999, 68: 0.788060922, 69: 0.7833455859999999, 70: 0.783237411, 71: 0.781810415, 72: 0.77947656, 73: 0.775430937, 74: 0.769843183, 75: 0.763548283, 76: 0.76318018, 77: 0.75891367, 78: 0.7588845790000001, 79: 0.758045414, 80: 0.7545263740000001, 81: 0.7514679670000001, 82: 0.74697755, 83: 0.74597623, 84: 0.743042806, 85: 0.740900129, 86: 0.740844543, 87: 0.7246525220000001, 88: 0.7133019070000001, 89: 0.7124335999999999, 90: 0.703856728, 91: 0.694475843, 92: 0.68836286, 93: 0.683978596, 94: 0.679002735, 95: 0.664945699, 96: 0.662761826, 97: 0.649950991, 98: 0.638550239, 99: 0.60593566, 100: 0.603891537, 101: 0.602900777, 102: 0.594660442, 103: 0.565978017}, 'Rolling Percentage': {0: 0.009615385, 1: 0.019230768999999998, 2: 0.028846154, 3: 0.038461537999999997, 4: 0.048076923, 5: 0.057692308, 6: 0.067307692, 7: 0.076923077, 8: 0.086538462, 9: 0.096153846, 10: 0.10576923099999999, 11: 0.115384615, 12: 0.125, 13: 0.134615385, 14: 0.144230769, 15: 0.153846154, 16: 0.16346153800000002, 17: 0.173076923, 18: 0.182692308, 19: 0.192307692, 20: 0.201923077, 21: 0.21153846199999998, 22: 0.22115384600000002, 23: 0.23076923100000002, 24: 0.240384615, 25: 0.25, 26: 0.259615385, 27: 0.269230769, 28: 0.278846154, 29: 0.288461538, 30: 0.298076923, 31: 0.307692308, 32: 0.317307692, 33: 0.326923077, 34: 0.33653846200000004, 35: 0.346153846, 36: 0.355769231, 37: 0.365384615, 38: 0.375, 39: 0.384615385, 40: 0.394230769, 41: 0.403846154, 42: 0.41346153799999996, 43: 0.423076923, 44: 0.43269230799999997, 45: 0.44230769200000003, 46: 0.451923077, 47: 0.46153846200000004, 48: 0.471153846, 49: 0.480769231, 50: 0.490384615, 51: 0.5, 52: 0.509615385, 53: 0.519230769, 54: 0.528846154, 55: 0.538461538, 56: 0.548076923, 57: 0.557692308, 58: 0.567307692, 59: 0.576923077, 60: 0.586538462, 61: 0.596153846, 62: 0.605769231, 63: 0.615384615, 64: 0.625, 65: 0.634615385, 66: 0.644230769, 67: 0.653846154, 68: 0.663461538, 69: 0.673076923, 70: 0.682692308, 71: 0.692307692, 72: 0.701923077, 73: 0.711538462, 74: 0.721153846, 75: 0.7307692309999999, 76: 0.740384615, 77: 0.75, 78: 0.759615385, 79: 0.7692307690000001, 80: 0.778846154, 81: 0.788461538, 82: 0.798076923, 83: 0.807692308, 84: 0.817307692, 85: 0.826923077, 86: 0.836538462, 87: 0.846153846, 88: 0.8557692309999999, 89: 0.865384615, 90: 0.875, 91: 0.884615385, 92: 0.8942307690000001, 93: 0.903846154, 94: 0.913461538, 95: 0.923076923, 96: 0.932692308, 97: 0.942307692, 98: 0.951923077, 99: 0.961538462, 100: 0.971153846, 101: 0.9807692309999999, 102: 0.990384615, 103: 1.0}} )