小编JA-*_*sta的帖子

如何使用 Python Pandas to_datetime 方法修复 ParserError:year 0 is out of range:0000-00-00

我正在尝试将列“travel_start”转换为日期时间对象。

Dashboard["travel_start"] = pd.to_datetime(Dashboard["travel_start"])
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

ParserError: year 0 is out of range: 0000-00-00
Run Code Online (Sandbox Code Playgroud)

当我尝试从数据框中的列中过滤“travel_start”列时。我看到下面的日期:

4922     0000-00-00
5592     0000-00-00
6647     0000-00-00
6796     0000-00-00
6941     0000-00-00
8223     0000-00-00
8391     0000-00-00
10137    0000-00-00
10197    0000-00-00
10744    0000-00-00
11128    0000-00-00
12304    0000-00-00
12511    0000-00-00
13307    0000-00-00
13681    0000-00-00
14381    0000-00-00
15160    0000-00-00
16330    0000-00-00
17734    0000-00-00
18148    0000-00-00
19389    0000-00-00
19643    0000-00-00
20372    0000-00-00
21412    0000-00-00
21757    0000-00-00
21879    0000-00-00
21978    0000-00-00
23216    0000-00-00
24375    0000-00-00
25660    0000-00-00
Run Code Online (Sandbox Code Playgroud)

对此的计数表明,这种情况发生了 56 次,我认为使用这些错误将其转换为 NaT 并不明智。你认为我可以把它们改成什么?或者做?

非常感谢您的意见。谢谢

datetime dataframe string-to-datetime pandas

8
推荐指数
1
解决办法
2万
查看次数

如何修复:组件的 Children 属性是列表的列表,而不仅仅是 Python 中带有 Plotly-dash 的列表

我正在尝试使用绘图和破折号构建一个简单的网络仪表板。这是我想要获得的结构:

app = dash.Dash(__name__)

def Build_home_page():
    """
    build_welcome_banner [summary]

    [extended_summary]

    Returns
    -------
    [type]
        [description]
    """    ""
    
    return [
        html.Div(
            id="banner",
            className="box",
            children=[
                html.Div(
                    id="welcome-user",
                    children=[
                        html.H1("WELCOME TO THE DATA SCIENCE"),
                        html.H1("AND MACHINE LEARNING PLATFORM"),
                        html.Hr(className="tickline"),
                        html.Br(),
                        html.P(id="welcome-text1",
                               children= [
                                   "That provides you with the tools that allow you to explore your data seemlessly and"
                                   ]),
                        html.P(id= "welcome-text2",
                               children= [
                                   "get actionable insights from your data and allows you to easily apply Machine learning models to make predictions with your data" …
Run Code Online (Sandbox Code Playgroud)

python-3.x plotly plotly-dash plotly-python

5
推荐指数
1
解决办法
7627
查看次数

在 plotly 中显式设置箱线图的颜色

我用来plotly express绘制boxplot如下图所示:

px.box(data_frame=df, 
       y="price", 
       x="products",
       points="all")
Run Code Online (Sandbox Code Playgroud)

然而,产品的盒盆以相同的颜色显示。它们是四种产品。我想用不同的颜色为每个颜色着色,使用附加参数color_discrete_sequence不起作用。

python python-3.x plotly plotly-python plotly-express

4
推荐指数
1
解决办法
5188
查看次数

ModuleNotFoundError: 没有名为“SessionState”的模块

当我导入SessionState. 我收到以下错误:ModuleNotFoundError: No module named 'SessionState' 使用 SessionState 时

这是我的代码的片段:

from multiprocessing import Process
import streamlit as st
import SessionState
import time
import os
import signal

st.sidebar.title("Controls")
start = st.sidebar.button("Start")
stop = st.sidebar.button("Stop")

state = SessionState.get(pid=None)
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这个问题,你是如何解决的?网上没有资源

python session-state python-3.x streamlit

3
推荐指数
1
解决办法
2885
查看次数

有没有办法组合多种类型进行打字

使用类型提示库typing是否可以组合两种类型?我想要一个 singlestr或 alist of str作为参数。见下文:

from typing import Dict, Optional, List


def run_ml(
        estimator: Estimator,
        parameters: Optional[Dict[str, List[str]]] = None,
):
Run Code Online (Sandbox Code Playgroud)

python type-hinting python-3.x

3
推荐指数
1
解决办法
2800
查看次数

如何在设计 pandas DataFrame 时使索引从 1 开始

造型后我pandas DataFramePython。我注意到索引从 开始0。我如何让它开始于1.

我尝试这样做df.index = np.arange(1, len(df)),但它给了我一个错误:ValueError: Length mismatch: Expected axis has 1119 elements, new values have 1118 elements

这是我的代码供您审查:

from IPython.display import HTML

df.index = np.arange(1, len(df))

def hover(hover_color="#FF5733"):
    return dict(selector="tbody tr:hover",
            props=[("background-color", "%s" % hover_color)])

styles = [
    #table properties
    dict(selector=" ", 
         props=[("margin","0"),
                ("font-family",'calibri'),
                ("border-collapse", "collapse"),
                ("border","none"),
                ("border", "2px solid #ccf")
                   ]),

    #header color - optional
    dict(selector="thead", 
         props=[("background-color","#489AF3")
               ]),

    #background shading
    dict(selector="tbody tr:nth-child(even)",
         props=[("background-color", "#fff")]),
    dict(selector="tbody tr:nth-child(odd)", …
Run Code Online (Sandbox Code Playgroud)

css python python-3.x pandas

2
推荐指数
1
解决办法
1978
查看次数

如何修复:TypeError: relplot() 在使用 seaborn 绘制线图时获得了参数 'x' 的多个值

我正在尝试与seaborn 一起绘制line plot

使用:

sns.relplot(Data, x="InvoiceYearMonth", y="price", hue="company")
Run Code Online (Sandbox Code Playgroud)

给我一个错误:

TypeError: relplot() got multiple values for argument 'x'
Run Code Online (Sandbox Code Playgroud)

可能出什么问题了?

这是我的数据样本供您参考:

    InvoiceYearMonth  company       price
0     202001          companyA      1509.40
1     202001          companyB      469.00
2     202001          companyC      358.81
3     202002          companyD      870.00
4     202002          companyE      465.58
5     202002          companyF      563.00
6     202003          companyG      1140.00
Run Code Online (Sandbox Code Playgroud)

python matplotlib dataframe python-3.x seaborn

0
推荐指数
1
解决办法
6501
查看次数