I am trying to build a plot using ggplot(aes(x="order_date", y="total_price"), data=data_) and this is the code:
# Core Python Data Analysis
from numpy.core.defchararray import index
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Plotting
from plotnine import (
ggplot, aes,
geom_col, geom_line, geom_smooth,
facet_wrap,
scale_y_continuous, scale_x_datetime,
labs,
theme, theme_minimal, theme_matplotlib,
expand_limits,
element_text
)
sales_by_months = df[[ 'order_date', 'total_price' ]] \
.set_index('order_date') \
.resample(rule='MS') \
.aggregate(np.sum) \
.reset_index()
data_ = sales_by_months
ggplot(aes(x="order_date", y="total_price"), data=data_)
I install all the libraries prior to this code. I get this error:
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_28504\2472174790.py in <module>
----> 1 ggplot(aes(x="order_date", y="total_price"), data=data_)
TypeError: __init__() got multiple values for argument 'data'
Can someone please hep me to solve it or show me why am I having this bug?
WINDOW11, JUPYTER NOTEBOOK, PYTHON3
CodePudding user response:
The first argument you're passing into ggplot
is data
by default (because it's in first place in the source code, and you didn't provide any keyword), but then you pass another data
argument later (with keyword).
This is why such an error happens.
Try to specify the keyword for the first argument, which is mapping
.
Also, another tip which is not necessary but can help to improve readability and have a code more straight: put the data
argument first, then mapping
in second.
So you would have: ggplot(data=data_, mapping=aes(x="order_date", y="total_price"))