The code is copied from this main link.
Here's the code, that showed me the error:
import pandas as pd
import seaborn as sns
year = 2022
url = f"https://home.treasury.gov/resource-center/data-chart-center/interest-rates/TextView?type=daily_treasury_yield_curve&field_tdr_date_value={year}"
table_list = pd.read_html(url)
df = table_list[0]
def clean_df(df):
df['Date'] = pd.to_datetime(df['Date'])# .apply(pd.Timestamp.toordinal)
df = df.drop(['20 YR', '30 YR', 'Extrapolation Factor',
'8 WEEKS BANK DISCOUNT', 'COUPON EQUIVALENT', '52 WEEKS BANK DISCOUNT',
'COUPON EQUIVALENT.1'], axis=1)
return df
df = clean_df(df)
sns.heatmap(df)
this is showing the error:
TypeError Traceback (most recent call last)
<ipython-input-237-10d89d2ec370> in <module>()
----> 1 sns.heatmap(df);
3 frames
/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
/usr/local/lib/python3.7/dist-packages/seaborn/matrix.py in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, xticklabels, yticklabels, mask, ax, **kwargs)
540 plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
541 annot_kws, cbar, cbar_kws, xticklabels,
--> 542 yticklabels, mask)
543
544 # Add the pcolormesh kwargs here
/usr/local/lib/python3.7/dist-packages/seaborn/matrix.py in __init__(self, data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, cbar, cbar_kws, xticklabels, yticklabels, mask)
158 # Determine good default values for the colormapping
159 self._determine_cmap_params(plot_data, vmin, vmax,
--> 160 cmap, center, robust)
161
162 # Sort out the annotations
/usr/local/lib/python3.7/dist-packages/seaborn/matrix.py in _determine_cmap_params(self, plot_data, vmin, vmax, cmap, center, robust)
191
192 # plot_data is a np.ma.array instance
--> 193 calc_data = plot_data.astype(float).filled(np.nan)
194 if vmin is None:
195 if robust:
TypeError: float() argument must be a string or a number, not 'Timestamp'
to check for solution on stackoverflow I got these: link1 and link2; Which solves the error, but while plotting on seaborn, all of the data are shown in black in the image.
I have used the solutions on this link also and I am still facing the same issue.
Further using plotpy as in the main link also giving me a same kind of result. How to avoid this issue?
I have no permission to show image here.