Just created this class to print some interative charts but I've been getting different errors. The most recent is :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-ee093d057bde> in <module>
25
26 if __name__ == '__main__':
---> 27 ChartsPropylene()
<ipython-input-29-ee093d057bde> in __init__(self)
1 class ChartsPropylene():
2 def __init__(self):
----> 3 self.start_date=dt(2008, 4, 24)
4 self.end_date=dt(2020, 5, 24)
5 self.dates=pd.date_range(self.start_date, self.end_date, freq='D')
the class code I created is the following:
import sys, os
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import ipywidgets as widgets
from ipywidgets import interact
import cufflinks as cf
import datetime as dt
from IPython import display
class ChartsPropylene():
def __init__(self):
self.start_date=dt(2008, 4, 24)
self.end_date=dt(2020, 5, 24)
self.dates=pd.date_range(self.start_date, self.end_date, freq='D')
self.options=[(date.strftime(' %d %b %y '), date) for date in self.dates]
self.index=(0, len(self.options)-1)
self.selection_range_slider=widgets.SelectionRangeSlider(options=self.options, index=self.index, description='Dates', orientation='horizontal', layout={'width':'600px'})
def __printChart__(self):
display(self.selection_range_slider)
x=self.selection_range_slider.get_interact_value()[0].toordinal()
y=self.selection_range_slider.get_interact_value()[1].toordinal()
abs1=abs(y-x)
plt.figure(figsize=(18, 10))
sns.set(style="darkgrid")
palette2=sns.color_palette("mako_r", 3)
sns.lineplot(x="Date", y="Value", hue='Std_Type', style='Value_Type', sizes=(.25, 2.5), ci='sd', estimator=None, lw=1, palette=palette2, data=tbl4)
rectangle1=plt.Rectangle(xy=(x, 500), width=abs1, height=500, linewidth=2, color='red', facecolor='blue', joinstyle='round', alpha=0.1, fill=True)
rectangle2=plt.Rectangle(xy=(x, 500), width=abs1, height=500, linewidth=2, color='red', facecolor='blue', joinstyle='round', alpha=1, fill=False)
plt.gca().add_patch(rectangle1)
plt.gca().add_patch(rectangle2)
plot.show(10)
What did I do wrong?
I tried to import the class and run but the same error appeared.
datetime
(dt
in your code) is not callable, it's a module.
You meant dt.date(2008, 4, 24)
, or perhaps import datetime.date as dt
(the first makes more sense if you call it dt, I guess..). datetime.date
is a callable class inside datetime
.
Not mentioned in your question but worth mentioning (to not be confused with at a later stage) is datetime.datetime
, another callable class inside datetime
.