Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Datetime 绘图日期时间_Datetime_Seaborn - Fatal编程技术网

Datetime 绘图日期时间

Datetime 绘图日期时间,datetime,seaborn,Datetime,Seaborn,我使用的数据集的日期时间end\u date和编号trip\u length data = {'end_date': '2015-02-19 15:46:00', 'trip_length': 300}`) data['end_date'] = pd.to_datetime(data['end_date'])` data['end_just_date'] = data.end_date.dt.date import seaborn as sns sns.lmplot('end_just_dat

我使用的数据集的日期时间
end\u date
和编号
trip\u length

data = {'end_date': '2015-02-19 15:46:00', 'trip_length': 300}`)
data['end_date'] = pd.to_datetime(data['end_date'])`
data['end_just_date'] = data.end_date.dt.date

import seaborn as sns
sns.lmplot('end_just_date', 'trip_length', data=data)
我想绘制一个给定年份中所有天数的
trip\u length
散点图。我创建了一个只包含日期的列,但当我将其打印为x变量时,出现以下错误:

TypeError:float()参数必须是字符串或数字


有没有一种方法可以根据月份将日期转换为天数的整数?

Edit2:有一种更好的方法,如M.Waskom所建议的:

g = sns.FacetGrid(less_than_two_days)
g = (g.map(plt.scatter,'trip_length','end_date'))
plt.show()
编辑:可以在x轴上绘制年、月和日,如下所示:

less_than_two_days['end_yyyymmdd'] = (
    less_than_two_days['end_date'].dt.year.astype(str) + 
    less_than_two_days['end_date'].dt.month.astype(str).str.zfill(2) + 
    less_than_two_days['end_date'].dt.day.astype(str).str.zfill(2))

less_than_two_days['end_yyyymmdd'] = less_than_two_days['end_yyyymmdd'].astype(int)
然后,要使用日期标记x轴,请执行以下操作:

ax = sns.lmplot('end_yyyymmdd', 'trip_length', data=df)
ax.set_xticklabels(df['end_date'])
顺便说一句,这感觉像是一种解决办法,是因为:


旧答案:看起来您的数据帧被称为
少于两天
。如果是这样的话,您可以这样做以在其自己的列中获取一年中的某一天:

less_than_two_days['end_day_of_year'] = less_than_two_days['end_date'].dt.dayofyear
然后进行绘图:

sns.lmplot('end_day_of_year', 'trip_length', data=less_than_two_days)

对在我的问题中,我没有很好地解释这一点,但是
少于两天的
数据包括四年的数据,但是是一个总少于两天的行程长度的过滤数据集。为了澄清这一点,我将改变我上面的问题。我为年、月和日单独制作了一列,但不知道如何在x轴上一次将它们全部绘制成一行。有什么想法?谢谢。我遵循了这些步骤,但不理解错误:
ValueError:第一个参数必须是序列。是的,行得通。为了标记轴,我可以将其解析回箱子的日期。这似乎是一个非常常见的操作,也许我忽略了一个内置的datetime。@SioKCronin:添加了如何标记x轴的示例。让我知道这是怎么回事。哈!我喜欢这样。我对让标签直接从它的数据说话是非常纯粹的。