草庐IT

datetime_column

全部标签

python bson.errors.InvalidDocument : Cannot encode object: datetime. 日期 (2015, 3, 1)

我有以下功能:#thisisinamodulecalled'dbw_lib'defdateTimeOuput(start_days_back,end_days_back):start_delta=datetime.timedelta(days=start_days_back)end_delta=datetime.timedelta(days=end_days_back)start_date=datetime.date.today()-start_deltaend_date=datetime.date.today()-end_deltareturnstart_date,end_dated

python - datetime.strptime() 抛出 'does not match format' 错误

我明白了timedata'19/Apr/2011:22:12:39'doesnotmatchformat'%d/%b/%y:%H:%M:%S'当使用datetime.strptime('19/Apr/2011:22:12:39','%d/%b/%y:%H:%M:%S')我做错了什么? 最佳答案 试试%d/%b/%Y:%H:%M:%S-%y现在表示11。您可以使用date轻松地“调试”日期时间格式(在shell而不是python上,我的意思是,假设您正在运行GNU/Linux或类似系统):date'+%d/%b/%Y:%H:%M:%S

python - 分析异常 : u"cannot resolve 'name' given input columns: [ list] in sqlContext in spark

我尝试了一个简单的例子:data=sqlContext.read.format("csv").option("header","true").option("inferSchema","true").load("/databricks-datasets/samples/population-vs-price/data_geo.csv")data.cache()#Cachedataforfasterreusedata=data.dropna()#droprowswithmissingvaluesdata=data.select("2014Populationestimate","2015

python - pd.Timestamp 与 np.datetime64 : are they interchangeable for selected uses?

这个问题的动机是ananswer到questiononimprovingperformance在pandas中与DatetimeIndex进行比较时。该解决方案通过df.index.values将DatetimeIndex转换为numpy数组,并将该数组与np.datetime64对象。这似乎是从此比较中检索bool数组的最有效方法。pandas的一位开发人员对这个问题的反馈是:“这些通常不一样。提供numpy解决方案通常是一种特殊情况,不推荐使用。”我的问题是:对于一部分操作,它们是否可以互换?我很感激DatetimeIndex提供了更多功能,但我只需要基本功能,例如切片和索引。对于

python - SqlAlchemy 不接受 DateTime 列中的 datetime.datetime.now 值

我应该首先提到我通过Flask-SqlAlchemy使用SqlAlchemy。我认为这不会影响问题,但如果有影响,请告诉我。这是我在SqlAlchemy中运行create_all函数时收到的错误消息的相关部分InterfaceError:(InterfaceError)错误绑定(bind)参数4-可能是不支持的类型。u'INSERTINTOpodcasts(feed_url,title,url,last_updated,feed_data)VALUES(?,?,?,?,?)'(u'http://example.com/feed',u'PodcastShowTitle',u'http:/

python - 为什么找不到 Python datetime time delta?

我正在尝试以mmddyyyy格式制作一组日期。日期将从当天开始,然后到future两周。所以这一切都取决于开始日期。当我运行我的代码时,我收到一条错误消息:Traceback(mostrecentcalllast):File"timeTest.py",line8,inday=datetime.timedelta(days=i)AttributeError:typeobject'datetime.datetime'hasnoattribute'timedelta'我不确定为什么会这样,因为在网上搜索后,我注意到人们以这种方式使用“timedelta”。这是我的代码:importtimef

python - 为什么 datetime.now() 和 datetime.today() 在我的电脑上显示 UTC 时间而不是本地时间?

datetime.now()和datetime.today()在我的计算机上返回UTC时间,即使thedocumentation说它们应该返回本地时间。这是我运行的脚本:#!/usr/bin/pythonimporttimeimportdatetimeif__name__=="__main__":print(datetime.datetime.now())print(datetime.datetime.today())print(datetime.datetime.fromtimestamp(time.time()))这是输出:2017-11-2922:47:35.3399142017

python - 如何直接从 datetime.datetime 子模块导入 now()

背景:我在Python程序中有几个重复调用的紧密循环,其中包括datetime.datetime.now()方法,以及datetime.datetime.min和datetime.datetime.max属性。为了优化,我想将它们导入本地命名空间,避免重复的、不必要的模块层次结构名称查找,如下所示:fromdatetime.datetimeimportnow,min,max但是,Python会提示:Traceback(mostrecentcalllast):File"my_code.py",line1,infromdatetime.datetimeimportnow,min,maxIm

python - 编程错误 : column "product" is of type product[] but expression is of type text[] enum postgres

我想保存枚举数组。我有以下内容:CREATETABLEpublic.campaign(idintegerNOTNULL,productproduct[])产品是一个枚举。在Django中我是这样定义的:PRODUCT=(('car','car'),('truck','truck'))classCampaign(models.Model):product=ArrayField(models.CharField(null=True,choices=PRODUCT))但是,当我写下以下内容时:campaign=Campaign(id=5,product=["car","truck"])cam

python - SQLAlchemy 过滤器查询 "column LIKE ANY (array)"

嗨,SQLAlchemy专家们,这里有一个棘手的问题:我正在尝试编写一个解析为类似内容的查询:SELECT*FROMMyTablewheremy_columnLIKEANY(array['a%','b%'])使用SQLAlchemy:foo=['a%','b%']#thisworks,butisdirtyandsillyDBSession().query(MyTable).filter("my_columnLIKEANY(array["+",".join(["'"+f+"'"forfintoken.tree_filters])+"])")#somethinglikethisshould