Python Forum
Invalid format specifier Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid format specifier Error
#1
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
Reply
#2
Please show associated code.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 723 Sep-05-2023, 12:50 PM
Last Post: ToniE
  error: invalid command 'egg_info' TimTu 0 965 Jul-27-2023, 07:30 AM
Last Post: TimTu
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,099 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Date format error getting weekday value Aggie64 2 1,427 May-29-2022, 07:04 PM
Last Post: Aggie64
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 3,183 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 3,283 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  Invalid syntax error - need help fixing calgk01 3 3,308 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Error on nested loop : Invalid syntax dvazquezgu 3 3,244 Nov-25-2020, 10:04 AM
Last Post: palladium
  Invalid Syntax error Dave1835 2 2,180 Sep-21-2020, 04:38 AM
Last Post: perfringo
  invalid keyword arguments error sagpal 3 2,415 Jun-04-2020, 10:24 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020