Error when visualizing data in kepler gl in jupyter notebook

1.4k views Asked by At

I want to visualize data on a kepler gl map using a jupyter notebook. I imported data from an xlsx file and selected one sheet (a DataFrame object). After that, I added this data to the Kepler map and got an error: ValueError: NaTType does not support strftime

sales_sheets2 = pd.read_excel("Sales_with_coordinates.xlsx", sheet_name=None)
data = sales_sheets2['Feb 2014']

from keplergl import KeplerGl
map_2 = KeplerGl(height=400)
map_2.add_data(data=data, name='data_1')
map_2

How to solve this problem ? Is there a problem with the Pandas DataFrame ? I found several articles about this error, but they were all related to converting calendar data to a different format, but I don't understand how this works in Kepler.

This is TraceBack

User Guide: https://docs.kepler.gl/docs/keplergl-jupyter
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-f3128ba8751f> in <module>
      1 from keplergl import KeplerGl
      2 map_2 = KeplerGl(height=400)
----> 3 map_2.add_data(data=a, name='data_1')
      4 map_2

~/Anaconda3/lib/python3.8/site-packages/keplergl/keplergl.py in add_data(self, data, name)
    134         copy.update({name: normalized})
    135 
--> 136         self.data = copy
    137 
    138     def _repr_html_(self, data=None, config=None, read_only=False, center_map=False):

~/Anaconda3/lib/python3.8/site-packages/traitlets/traitlets.py in __set__(self, obj, value)
    602             raise TraitError('The "%s" trait is read-only.' % self.name)
    603         else:
--> 604             self.set(obj, value)
    605 
    606     def _validate(self, obj, value):

~/Anaconda3/lib/python3.8/site-packages/traitlets/traitlets.py in set(self, obj, value)
    591             # we explicitly compare silent to True just in case the equality
    592             # comparison above returns something other than True/False
--> 593             obj._notify_trait(self.name, old_value, new_value)
    594 
    595     def __set__(self, obj, value):

~/Anaconda3/lib/python3.8/site-packages/traitlets/traitlets.py in _notify_trait(self, name, old_value, new_value)
   1215 
   1216     def _notify_trait(self, name, old_value, new_value):
-> 1217         self.notify_change(Bunch(
   1218             name=name,
   1219             old=old_value,

~/Anaconda3/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in notify_change(self, change)
    603             if name in self.keys and self._should_send_property(name, getattr(self, name)):
    604                 # Send new state to front-end
--> 605                 self.send_state(key=name)
    606         super(Widget, self).notify_change(change)
    607 

~/Anaconda3/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in send_state(self, key)
    487             state, buffer_paths, buffers = _remove_buffers(state)
    488             msg = {'method': 'update', 'state': state, 'buffer_paths': buffer_paths}
--> 489             self._send(msg, buffers=buffers)
    490 
    491 

~/Anaconda3/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in _send(self, msg, buffers)
    735         """Sends a message to the model in the front-end."""
    736         if self.comm is not None and self.comm.kernel is not None:
--> 737             self.comm.send(data=msg, buffers=buffers)
    738 
    739     def _repr_keys(self):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/comm/comm.py in send(self, data, metadata, buffers)
    120     def send(self, data=None, metadata=None, buffers=None):
    121         """Send a message to the frontend-side version of this comm"""
--> 122         self._publish_msg('comm_msg',
    123             data=data, metadata=metadata, buffers=buffers,
    124         )

~/Anaconda3/lib/python3.8/site-packages/ipykernel/comm/comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
     63         data = {} if data is None else data
     64         metadata = {} if metadata is None else metadata
---> 65         content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
     66         self.kernel.session.send(self.kernel.iopub_socket, msg_type,
     67             content,

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    189         out = {}
    190         for k,v in iteritems(obj):
--> 191             out[unicode_type(k)] = json_clean(v)
    192         return out
    193     if isinstance(obj, datetime):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in <listcomp>(.0)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in <listcomp>(.0)
    175 
    176     if isinstance(obj, list):
--> 177         return [json_clean(x) for x in obj]
    178 
    179     if isinstance(obj, dict):

~/Anaconda3/lib/python3.8/site-packages/ipykernel/jsonutil.py in json_clean(obj)
    192         return out
    193     if isinstance(obj, datetime):
--> 194         return obj.strftime(ISO8601)
    195 
    196     # we don't understand it, it's probably an unserializable object

pandas/_libs/tslibs/nattype.pyx in pandas._libs.tslibs.nattype._make_error_func.f()

ValueError: NaTType does not support strftime
1

There are 1 answers

0
Aurit arius On

Solved ! I just droped all Na values, using data = data.dropna()