代码之家  ›  专栏  ›  技术社区  ›  Nikko

绘图日期时间.time在seaborn

  •  2
  • Nikko  · 技术社区  · 6 年前

    嗨,我很难和seaborn安排约会时间。我试图用x作为数据类型来绘制一个分类数据 datetime.time

    float() argument must be a string or a number, not 'datetime.time'
    

    这是我的df:

           toronto_time             description
    0      00:00:50                   STATS
    1      00:01:55                   STATS
    2      00:02:18                   ONLINE
    3      00:05:24                   STATS
    4      00:05:34                   STATS
    5      00:06:33                   OFFLINE
    

    这是我的密码:

    import matplotlib.pyplot as plt
    import seaborn as sns
    
    plt.style.use('seaborn-colorblind')
    
    plt.figure(figsize=(8,6))
    sns.swarmplot('toronto_time', 'description', data=df);
    plt.show()
    

    1 回复  |  直到 6 年前
        1
  •  4
  •   Joe    6 年前

    如果我理解正确,你可以这样做:

    import matplotlib.pyplot as plt
    import seaborn as sns
    df['toronto_time'] = pd.to_datetime(df['toronto_time']).dt.strftime('%H:%M:%S')
    sns.scatterplot(df['toronto_time'], df['description'])
    plt.show()
    

    enter image description here