Python Forum
Invalid format specifier Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Invalid format specifier Error (/thread-37704.html)



Invalid format specifier Error - Led_Zeppelin - Jul-11-2022

When I run the Seaborn/Python following code on my laptop computer, I get the following output

Error:
ValueError Traceback (most recent call last) Input In [24], in <cell line: 3>() 1 corr = df2.corr() 2 plt.figure(figsize=(24,24)) ----> 3 sns.heatmap(corr, annot=True, fmt = ".1ft") File ~\miniconda3\envs\pump-failure-pred\lib\site-packages\seaborn\_decorators.py:46, in _deprecate_positional_args.<locals>.inner_f(*args, **kwargs) 36 warnings.warn( 37 "Pass the following variable{} as {}keyword arg{}: {}. " 38 "From version 0.12, the only valid positional argument " (...) 43 FutureWarning 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs) File ~\miniconda3\envs\pump-failure-pred\lib\site-packages\seaborn\matrix.py:553, 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) 551 if square: 552 ax.set_aspect("equal") --> 553 plotter.plot(ax, cbar_ax, kwargs) 554 return ax File ~\miniconda3\envs\pump-failure-pred\lib\site-packages\seaborn\matrix.py:348, in _HeatMapper.plot(self, ax, cax, kws) 346 # Annotate the cells with the formatted values 347 if self.annot: --> 348 self._annotate_heatmap(ax, mesh) File ~\miniconda3\envs\pump-failure-pred\lib\site-packages\seaborn\matrix.py:256, in _HeatMapper._annotate_heatmap(self, ax, mesh) 254 lum = relative_luminance(color) 255 text_color = ".15" if lum > .408 else "w" --> 256 annotation = ("{:" + self.fmt + "}").format(val) 257 text_kwargs = dict(color=text_color, ha="center", va="center") 258 text_kwargs.update(self.annot_kws) ValueError: Invalid format specifier
Frankly, I cannot see the error. The line looks correct to me. I even tried to run it with single quotes around the format specifier. I got the same error.

What am I doing wrong?

Thanks in advance.

Respectfully,

LZ


RE: Invalid format specifier Error - Larz60+ - Jul-11-2022

Please show associated code.


RE: Invalid format specifier Error - Led_Zeppelin - Jul-11-2022

The code i question is:

corr = df2.corr()
plt.figure(figsize=(24,24))
sns.heatmap(corr, annot=True, fmt = ".1ft")    
I have already defined df2.

What am I doing wrong?

Respectfully,

LZ

PS
Wait, I think that know what is wrong. It should be:

fmt=' .1f' not fmt=' 1ft'

That is most likely the error.