Skip to content Skip to sidebar Skip to footer

Pandas Error With Basemap/proj For Map Plotting

I ran the Python code below that is an example of 'Plotting Maps: Visualizing Haiti Earthquake Crisis Data' on a book, Python for Data Analysis. Page 242-246 The code is supposed t

Solution 1:

This is resolved by changing m(cat_data.LONGITUDE, cat_data.LATITUDE) to m(cat_data.LONGITUDE.values, cat_data.LATITUDE.values), thanks to Alex Messina's finding.

With a little further study of mine, pandas changed that Series data of DataFrame (derived from NDFrame) should be passed with .values to a Cython function like basemap/proj since v0.13.0 released on 31 Dec 2013 as below.

Quote from github commit log of pandas:

+.. warning::
 +
 +   In0.13.0 since ``Series`` has internaly been refactored to no longer sub-class``ndarray``
 +   but instead subclass ``NDFrame``, you can **not pass** a ``Series`` directly as a ``ndarray`` typed parameter
 +   to a cython function. Instead pass the actual ``ndarray`` using the ``.values`` attribute of the Series.
 +
 +   Prior to 0.13.0
 +
 +   .. code-block:: python
 +
 +        apply_integrate_f(df['a'], df['b'], df['N'])
 +
 +   Use``.values`` to get the underlying ``ndarray``
 +
 +   .. code-block:: python
 +
 +        apply_integrate_f(df['a'].values, df['b'].values, df['N'].values)

You can find the corrected version of the example code here.

Post a Comment for "Pandas Error With Basemap/proj For Map Plotting"