简体   繁体   English

TypeError:__init__() 为参数“数据”获取了多个值

[英]TypeError: __init__() got multiple values for argument 'data'

I am trying to build a plot using ggplot(aes(x="order_date", y="total_price"), data=data_) and this is the code:我正在尝试使用 ggplot(aes(x="order_date", y="total_price"), data=data_) 构建 plot,这是代码:

    # 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 WINDOW11、JUPYTER 笔记本、Python3

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).默认情况下,您传递给ggplot的第一个参数是data (因为它在源代码中排在首位,并且您没有提供任何关键字),但是稍后您会传递另一个data参数(使用关键字)。 This is why such an error happens.这就是发生这种错误的原因。 Try to specify the keyword for the first argument, which is mapping .尝试为第一个参数指定关键字,即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.此外,另一个技巧不是必需的,但可以帮助提高可读性并使代码更直接:将data参数放在第一位,然后mapping放在第二位。

So you would have: ggplot(data=data_, mapping=aes(x="order_date", y="total_price"))所以你会有: ggplot(data=data_, mapping=aes(x="order_date", y="total_price"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:__init __()为参数&#39;n_splits&#39;获取了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' TypeError:__init __()为参数&#39;fieldnames&#39;获得了多个值 - TypeError: __init__() got multiple values for argument 'fieldnames' 类型错误:__init__() 为参数“strides”获得了多个值 - TypeError: __init__() got multiple values for argument 'strides' TypeError:__init__() 为参数“轴”获取了多个值 - TypeError: __init__() got multiple values for argument 'axes' Python TypeError:__ init __()为参数&#39;master&#39;获取了多个值 - Python TypeError: __init__() got multiple values for argument 'master' TypeError:__init __()为关键字参数“ choices”获得了多个值 - TypeError: __init__() got multiple values for keyword argument 'choices' TypeError:“ __ init __()为关键字参数&#39;name&#39;获得了多个值” - TypeError: “__init__() got multiple values for keyword argument 'name'” TypeError: __init__() 为参数 'center' 获得了多个值 - TypeError: __init__() got multiple values for argument 'center' TypeError:__ init __()得到关键字参数&#39;customer&#39;的多个值 - TypeError: __init__() got multiple values for keyword argument 'customer' 类型错误:__init__() 为参数“index”获得了多个值 - TypeError: __init__() got multiple values for argument 'index'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM