You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#matplot/pandas code
%matplotlib inline
star_wars.iloc[:,9:15].mean().plot.bar()
#equivalent altair code
means = star_wars.iloc[:,9:15].mean().to_frame().reset_index()
#this line is needed as altair needs an index and cannot take pd.Series
means = sums.rename(columns={0:'mean_ranking'})
# since df.reset_index() given unamed columns int headers, which altair cant handle, the column must be renamed
alt.Chart(means).mark_bar().encode(
x = 'index:N',
y = 'mean_ranking' #not '0:Q'
)
If one does not rename the column the following error occurs
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in to_dict(self, *args, **kwargs)
396 copy = self.copy()
397 original_data = getattr(copy, 'data', Undefined)
--> 398 copy.data = _prepare_data(original_data, context)
399
400 if original_data is not Undefined:
~/anaconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in _prepare_data(data, context)
90 # consolidate inline data to top-level datasets
91 if data_transformers.consolidate_datasets:
---> 92 data = _consolidate_data(data, context)
93
94 # if data is still not a recognized type, then return
~/anaconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in _consolidate_data(data, context)
57
58 if values is not Undefined:
---> 59 name = _dataset_name(values)
60 data = core.NamedData(name=name, **kwds)
61 context.setdefault('datasets', {})[name] = values
~/anaconda3/lib/python3.6/site-packages/altair/vegalite/v2/api.py in _dataset_name(values)
33 if isinstance(values, core.InlineDataset):
34 values = values.to_dict()
---> 35 values_json = json.dumps(values, sort_keys=True)
36 hsh = hashlib.md5(values_json.encode()).hexdigest()
37 return 'data-' + hsh
~/anaconda3/lib/python3.6/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
237 separators=separators, default=default, sort_keys=sort_keys,
--> 238 **kw).encode(obj)
239
240
~/anaconda3/lib/python3.6/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
~/anaconda3/lib/python3.6/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
TypeError: '<' not supported between instances of 'int' and 'str'
it seems this might be the wide-form, long-form problem rearing it's head?
The text was updated successfully, but these errors were encountered:
If one does not rename the column the following error occurs
it seems this might be the wide-form, long-form problem rearing it's head?
The text was updated successfully, but these errors were encountered: