Python Forum
scatter plot error - possibly data type - TypeError: nan is not a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scatter plot error - possibly data type - TypeError: nan is not a string
#1
Hi,

Can anyone help me with this error?
I suspect it is something to do with the data type, but don't know how to resolve.
I'm trying to plot a 2 user system dates against each other and am getting the error below.

print(type(DialogUsers.TRDAT)) <class 'pandas.core.series.Series'> plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) plt.show() 
---------------------------------------------------------------------------
Error:
TypeError Traceback (most recent call last) <ipython-input-7-3277b90008cc> in <module>() ----> 1 plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) 2 plt.show() ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs) 3473 vmin=vmin, vmax=vmax, alpha=alpha, 3474 linewidths=linewidths, verts=verts, -> 3475 edgecolors=edgecolors, data=data, **kwargs) 3476 finally: 3477 ax._hold = washold ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1865 "the Matplotlib list!)" % (label_namer, func.__name__), 1866 RuntimeWarning, stacklevel=2) -> 1867 return func(ax, *args, **kwargs) 1868 1869 inner.__doc__ = _add_data_doc(inner.__doc__, ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs) 4245 edgecolors = 'face' 4246 -> 4247 self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) 4248 x = self.convert_xunits(x) 4249 y = self.convert_yunits(y) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_unit_info(self, xdata, ydata, kwargs) 2170 # we only need to update if there is nothing set yet. 2171 if not self.yaxis.have_units(): -> 2172 self.yaxis.update_units(ydata) 2173 2174 # process kwargs 2nd since these will override default units ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data) 1467 neednew = self.converter != converter 1468 self.converter = converter -> 1469 default = self.converter.default_units(data, self) 1470 if default is not None and self.units is None: 1471 self.set_units(default) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis) 113 # default_units->axis_info->convert 114 if axis.units is None: --> 115 axis.set_units(UnitData(data)) 116 else: 117 axis.units.update(data) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data) 180 self._counter = itertools.count(start=0) 181 if data is not None: --> 182 self.update(data) 183 184 def update(self, data): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data) 199 for val in OrderedDict.fromkeys(data): 200 if not isinstance(val, VALID_TYPES): --> 201 raise TypeError("{val!r} is not a string".format(val=val)) 202 if val not in self._mapping: 203 self._mapping[val] = next(self._counter) TypeError: nan is not a string
Thanks,
CiarĂ¡n
Reply
#2
plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) plt.show() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-7-3277b90008cc> in <module>() ----> 1 plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) 2 plt.show() ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs) 3473 vmin=vmin, vmax=vmax, alpha=alpha, 3474 linewidths=linewidths, verts=verts, -> 3475 edgecolors=edgecolors, data=data, **kwargs) 3476 finally: 3477 ax._hold = washold ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1865 "the Matplotlib list!)" % (label_namer, func.__name__), 1866 RuntimeWarning, stacklevel=2) -> 1867 return func(ax, *args, **kwargs) 1868 1869 inner.__doc__ = _add_data_doc(inner.__doc__, ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs) 4245 edgecolors = 'face' 4246 -> 4247 self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) 4248 x = self.convert_xunits(x) 4249 y = self.convert_yunits(y) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_unit_info(self, xdata, ydata, kwargs) 2170 # we only need to update if there is nothing set yet. 2171 if not self.yaxis.have_units(): -> 2172 self.yaxis.update_units(ydata) 2173 2174 # process kwargs 2nd since these will override default units ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data) 1467 neednew = self.converter != converter 1468 self.converter = converter -> 1469 default = self.converter.default_units(data, self) 1470 if default is not None and self.units is None: 1471 self.set_units(default) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis) 113 # default_units->axis_info->convert 114 if axis.units is None: --> 115 axis.set_units(UnitData(data)) 116 else: 117 axis.units.update(data) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data) 180 self._counter = itertools.count(start=0) 181 if data is not None: --> 182 self.update(data) 183 184 def update(self, data): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data) 199 for val in OrderedDict.fromkeys(data): 200 if not isinstance(val, VALID_TYPES): --> 201 raise TypeError("{val!r} is not a string".format(val=val)) 202 if val not in self._mapping: 203 self._mapping[val] = next(self._counter) TypeError: nan is not a string
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers deneme2 2 1,371 Feb-14-2025, 12:23 AM
Last Post: deneme2
  Changing client.get() method type based on size of data... dl0dth 1 1,275 Jan-02-2025, 08:30 PM
Last Post: dl0dth
Question TypeError: argument of type 'NoneType' is not iterable Tajaldeen 7 6,143 Nov-29-2024, 09:45 AM
Last Post: Tajaldeen
  A question on Boolean Data Type Hudjefa 5 2,006 Aug-13-2024, 11:03 AM
Last Post: Hudjefa
  TypeError: string indices must be integers, not 'str' LEMA 2 3,983 Jun-12-2024, 09:32 PM
Last Post: LEMA
  Value Error when Trying to Plot Filtered Waveforms mkohler 1 2,014 May-09-2024, 05:33 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 2,854 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  Wrong type error rowan_bradley 6 3,752 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 7,205 Jul-22-2023, 11:33 PM
Last Post: jhancock
  Likert survey data plot error Andrzej_Andrzej 6 4,446 Jul-16-2023, 10:11 PM
Last Post: deanhystad

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.