草庐IT

readable_date_ranges

全部标签

Python 将 long 转换为 date

我正在尝试将长整数转换为日期:classtimeStamp(object):defgetDateTime(self,longDate):myNumber=float(longDate)returnstr(datetime.datetime.fromtimestamp(time.ctime(myNumber)).strftime('%Y-%m-%d%H:%M:%S'))但是我有一个奇怪的错误:File"./index.py",line104,ingetDateTimereturnstr(datetime.datetime.fromtimestamp(time.ctime(myNumber

Python 索引错误 : tuple index out of range

非常感谢对此问题的反馈importsubprocessdefmain():'''Here'swherethewholethingstarts.'''#Editthisconstanttochangethefilenameinthegitlogcommand.FILE_NAME='file1.xml'#Dothegitdescribecommandtogetthetagnames.gitDescribe='gitdescribe--tags`gitrev-list--tags--max-count=2`'print('Invoking:{0}'.format(gitDescribe))p

python - `ValueError: A value in x_new is above the interpolation range.` - 除了不提升值还有什么其他原因?

我在scipyinterp1d函数中收到此错误。通常,如果x不是单调递增,就会产生此错误。importscipy.interpolateasspidefrefine(coarsex,coarsey,step):finex=np.arange(min(coarsex),max(coarsex)+step,step)intfunc=spi.interp1d(coarsex,coarsey,axis=0)finey=intfunc(finex)returnfinex,fineyfornum,tfileinenumerate(files):tfile=tfile.dropna(how='any

python - 我如何表示此正则表达式不会出现 "bad character range"错误?

有更好的方法吗?$pythonPython2.7.9(default,Jul162015,14:54:10)[GCC4.1.220080704(RedHat4.1.2-55)]onlinux2Type"help","copyright","credits"or"license"formoreinformation.>>>importre>>>re.sub(u'[\U0001d300-\U0001d356]',"","")Traceback(mostrecentcalllast):File"",line1,inFile"/home/fast/services/lib/python2.7/

python - 如何组合 range() 函数

对于我正在编写的某些代码,我需要从1-30跳过6进行迭代。我天真地尝试过的是a=range(1,6)b=range(7,31)foriina+b:printi有没有办法更有效地做到这一点? 最佳答案 使用itertools.chain:importitertoolsa=range(1,6)b=range(7,31)foriinitertools.chain(a,b):printi或者棘手的扁平化生成器表达式:a=range(1,6)b=range(7,31)foriin(xforyin(a,b)forxiny):printi或者跳过

python - TypeError : range() integer end argument expected, 有 float ?

我知道之前有人问过这个问题,但答案对我没有帮助:/我创建了一个函数,它在输入的平方最大值上运行一个for循环,从各方面来看我的代码是正确的......但它仍然要求浮点输入。defspiral(X,Y):x=y=0dx=0dy=0count=0foriinrange(max(X,Y)**2):if(-X/2.00andx==1-y):dx,dy=-dy,dxx,y=x+dx,y+dy打印螺旋(3.0,3.0)我得到这个错误:TypeError:range()integerendargumentexpected,gotfloat.但是当我尝试打印函数时我输入了3.0...那么我错过了什么?

python - 如何将 datetime.date 对象转换为 time.struct_time 对象?

我有一个python脚本,我需要比较两个日期。我有一个日期列表作为time.struct_time对象,我需要将其与几个datetime.date对象进行比较。如何将datetime.date对象转换为time.struct_time对象?或者我可以直接使用它们进行比较吗? 最佳答案 尝试使用date.timetuple().来自Python文档:Returnatime.struct_timesuchasreturnedbytime.localtime().Thehours,minutesandsecondsare0,andtheD

Python dateutil.parser 抛出 "ValueError: day is out of range for month"

我有以下代码可以在{Year}/{Month}这样的输入格式下正常运行,但涉及到1994/02时除外这是示例代码>>>importdateutil.parserasdtp>>>dtp.parse('1994/01')datetime.datetime(1994,1,29,0,0)>>>dtp.parse('1994/03')datetime.datetime(1994,3,29,0,0)>>>dtp.parse('1994/02')Traceback(mostrecentcalllast):File"",line1,inFile"/Users/antony/.virtualenvs/c

python - 如何在 python 中将 datetime.date 对象转换为 datetime.datetime?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Convertadatetime.dateobjectintoadatetime.datetimeobjectwithzerosforanymissingtimeattributes如何将datetime.dateobj转换为datetime.datetimeobj,默认为午夜?

python - 值错误 : day is out of range for month

我想将字符串从数据帧转换为日期时间。dfx=df.ix[:,'a']dfx=pd.to_datetime(dfx)但它给出了以下错误:ValueError:dayisoutofrangeformonth有人可以帮忙吗? 最佳答案 也许可以帮助将参数dayfirst=True添加到to_datetime,如果日期时间的格式是30-01-2016:dfx=df.ix[:,'a']dfx=pd.to_datetime(dfx,dayfirst=True)更通用的是使用参数format使用errors='coerce'将值替换为其他form