草庐IT

start_date

全部标签

Python isinstance() 返回带有 datetime.date 的错误

我正在尝试编译anold2008code.importdatetimeifisinstance(value,datetime.date):但是我得到一个错误:isinstance()arg2mustbeaclass,type,ortupleofclassesandtypesPythonExecutable:/usr/bin/python2.6PythonVersion:2.6.5我错过了什么? 最佳答案 我怀疑您导入了错误的日期时间:fromdatetimeimportdatetime改为使用:importdatetime

python - 错误 : 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte

我正在尝试执行以下操作kaggleassignmnet.我正在使用gensim包来使用word2vec。我能够创建模型并将其存储到磁盘。但是,当我尝试重新加载文件时,出现以下错误。-HP-dx2280-MT-GR541AV:~$pythonprog_w2v.pyTraceback(mostrecentcalllast):File"prog_w2v.py",line7,inmodels=gensim.models.Word2Vec.load_word2vec_format('300features_40minwords_10context.txt',binary=True)File"/u

python - 为什么在不指定关键字start时枚举执行速度较慢?

我在计时enumerate时注意到以下奇怪行为使用指定的默认start参数:In[23]:%timeitenumerate([1,2,3,4])Theslowestruntook7.18timeslongerthanthefastest.Thiscouldmeanthatanintermediateresultisbeingcached1000000loops,bestof3:511nsperloopIn[24]:%timeitenumerate([1,2,3,4],start=0)Theslowestruntook12.45timeslongerthanthefastest.This

python 和 Pandas : Combine columns into a date

在我的dataframe中,时间分为3列:year、month、day,例如这个:如何将它们转换成日期,以便进行时间序列分析?我能做到:df.apply(lambdax:'%s%s%s'%(x['year'],x['month'],x['day']),axis=1)给出:10951954111096195412109719541310981954141099195415110019541611011954171102195418110319541911041954110110519541111106195411211071954113但是接下来呢?编辑:这就是我最终得到的:fromda

python - 值错误 : Series lengths must match to compare when matching dates in Pandas

我提前为提出这样一个基本问题道歉,但我很困惑。这是一个非常简单的虚拟示例。我在Pandas中匹配日期时遇到一些问题,我不知道为什么。df=pd.DataFrame([[1,'2016-01-01'],[2,'2016-01-01'],[3,'2016-01-02'],[4,'2016-01-03']],columns=['ID','Date'])df['Date']=df['Date'].astype('datetime64')假设我想匹配上面df中的第1行。我事先知道我要匹配ID1。而且我也知道我想要的日期,事实上,我将直接从df的第1行提取该日期以使其无懈可击。some_id=1s

python - 如何在 pandas date_range 方法中包含结束日期?

从pd.date_range('2016-01','2016-05',freq='M',.strftime('%Y-%m')开始,最后一个月是2016-04,但我原以为是2016-05。在我看来,此函数的行为类似于range方法,其中结束参数不包含在返回数组中。有没有办法在不处理结束月份的字符串的情况下将结束月份包含在返回数组中? 最佳答案 一种无需自己弄清楚月末的方法。pd.date_range(*(pd.to_datetime(['2016-01','2016-05'])+pd.offsets.MonthEnd()),freq=

python - Matplotlib fill_between 不适用于 plot_date,还有其他选择吗?

我想像这样创建一个情节:代码:P.fill_between(DF.start.index,DF.lwr,DF.upr,facecolor='blue',alpha=.2)P.plot(DF.start.index,DF.Rt,'.')但是x轴上有日期,像这样(没有带):代码:P.plot_date(DF.start,DF.Rt,'.')问题是当x值是date_time对象时fill_between失败。有人知道解决方法吗?DF是一个pandasDataFrame。 最佳答案 如果您显示df是如何定义的,将会有所帮助。df.info(

python - Pandas 从日期获取年龄(例如 : date of birth)

我如何计算一个人的年龄(基于dob列)并使用新值向数据框添加一列?数据框如下所示:lnamefnamedob0DOELAURIE030119791BOURNEJASON061119782GRINCHXMAS121319883DOEJOHN11121986我尝试执行以下操作:now=datetime.now()df1['age']=now-df1['dob']但是,收到以下错误:TypeError:不支持的操作数类型-:'datetime.datetime'和'str' 最佳答案 importdatetimeasDTimportioi

python - json.dump - UnicodeDecodeError : 'utf8' codec can't decode byte 0xbf in position 0: invalid start byte

我有一个字典data我存储了:key-事件IDvalue-此事件的名称,其中value是UTF-8字符串现在,我想把这张map写到一个json文件中。我试过这个:withopen('events_map.json','w')asout_file:json.dump(data,out_file,indent=4)但这给了我错误:UnicodeDecodeError:'utf8'codeccan'tdecodebyte0xbfinposition0:invalidstartbyte现在,我也试过:withio.open('events_map.json','w',encoding='utf

javascript - Js Date 对象到 python datetime

我正在使用dhtmlxscheduler并将日期发送到django服务器进行处理。Dhtmlxscheduler为我提供了以下日期对象,提供的方法从下面第二行开始:end_date:SatNov19201101:00:00GMT-0500(EST)__proto__:InvalidDateconstructor:functionDate(){[nativecode]}getDate:functiongetDate(){[nativecode]}getDay:functiongetDay(){[nativecode]}getFullYear:functiongetFullYear(){[