Giter Site home page Giter Site logo

Comments (3)

fbourgey avatar fbourgey commented on August 16, 2024 1

Hello, I am working on it.

from pandas.

fbourgey avatar fbourgey commented on August 16, 2024

I updated the following

https://github.com/fbourgey/pandas/blob/feature-plot-weighted-kde/pandas/plotting/_core.py#L1449
https://github.com/fbourgey/pandas/blob/feature-plot-weighted-kde/pandas/plotting/_matplotlib/hist.py#L266

The code works.

Should we add one example in the function kde with the parameter weights?
Does this function need to be updated as well?

from pandas.

fbourgey avatar fbourgey commented on August 16, 2024

The following code gives

s = pd.Series([1, 2, 2.5, 3, 3.5, 4, 5])
ax = s.plot.kde()

Figure_0

Replacing with some weights produces

weights = pd.Series([0.1, 0.0, 0.0, 0.2, 0.3, 0.4, 0.9])
ax = s.plot.kde(weights=weights)

Figure_1

Using a Numpy Array works as well

weights = np.array([0.1, 0.4, 0.0, 0.2, 0.3, 0.4, 0.2])

However, passing a list instead

weights = [0.1, 0.4, 0.0, 0.2, 0.3, 0.4, 0.2]

raises the following error

  File "/Users/florianbourgey/projects/misc/pandas_gaussian_kde.py", line 7, in <module>
    ax = s.plot.kde(weights=weights)
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_core.py", line 1567, in kde
    return self(kind="kde", bw_method=bw_method, weights=weights, ind=ind, **kwargs)
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_core.py", line 1049, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_matplotlib/__init__.py", line 71, in plot
    plot_obj.generate()
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_matplotlib/core.py", line 500, in generate
    self._make_plot(fig)
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_matplotlib/hist.py", line 168, in _make_plot
    kwds["weights"] = type(self)._get_column_weights(self.weights, i, y)
  File "/Users/florianbourgey/projects/pandas/pandas/plotting/_matplotlib/hist.py", line 202, in _get_column_weights
    weights = weights[~isna(y)]

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.