Pandas error with basemap/proj for map plotting

后端 未结 1 709
故里飘歌
故里飘歌 2021-01-21 17:52

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

1条回答
  •  太阳男子
    2021-01-21 18:29

    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::
     +
     +   In 0.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.

    0 讨论(0)
提交回复
热议问题