python-dateutil

customize dateutil.parser century inference logic

房东的猫 提交于 2019-12-06 03:11:10
问题 I am working on old text files with 2-digit years where the default century logic in dateutil.parser doesn't seem to work well. For example, the attack on Pearl Harbor was not on dparser.parse("12/7/41") (which returns 2041-12-7). The buit-in century "threshold" to roll back into the 1900's seems to happen at 66: import dateutil.parser as dparser print(dparser.parse("12/31/65")) # goes forward to 2065-12-31 00:00:00 print(dparser.parse("1/1/66")) # goes back to 1966-01-01 00:00:00 For my

error 3 on dateutil/zoneinfo using cx_freeze and pandas

我的未来我决定 提交于 2019-12-06 01:42:43
问题 When I try to compile the hello.py file with cx_freeze, I get the following error with pandas 0.15.2 but no error with 0.15.1. Has someone any idea on how to correct it ? I have include the dateutil/zoneinfo files with the include_files function but the problem still occurs. hello.py: import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt print 'hello world' df_dates = pd.date_range(start='01/01/2013', freq='H', periods=100) df = pd.DataFrame(range(len(df

dateutil.relativedelta - How to get duration in days?

故事扮演 提交于 2019-12-05 00:56:54
I wish to get the total duration of a relativedelta in terms of days. Expected: dateutil.timedelta(1 month, 24 days) -> dateutil.timedelta(55 days) What I tried: dateutil.timedelta(1 month, 24 days).days -> 24 (WRONG) Is there a simple way to do this? Thanks! This one bothered me as well. There isn't a very clean way to get the span of time in a particular unit. This is partly because of the date-range dependency on units. relativedelta() takes an argument for months. But when you think about how long a month is, the answer is "it depends". With that said, it's technically impossible to

Inferring date format versus passing a parser

北慕城南 提交于 2019-12-05 00:20:12
Pandas internals question: I've been surprised to find a few times that explicitly passing a callable to date_parser within pandas.read_csv results in much slower read time than simply using infer_datetime_format=True . Why is this? Will timing differences between these two options be date-format-specific, or what other factors will influence their relative timing? In the below case, infer_datetime_format=True takes one-tenth the time of passing a date parser with a specified format. I would have naively assumed the latter would be faster because it's explicit. The docs do note, [if True,]

Using python pandas to parse CSV with date in format Year, Day, Hour, Min, Sec

自闭症网瘾萝莉.ら 提交于 2019-12-04 07:22:55
I have several CSV files with the format: Year,Day,Hour,Min,Sec.,P1'S1 2003, 1, 0, 0,12.22, 0.541 2003, 1, 1, 0,20.69, 0.708 2003, 1, 2, 0, 4.95, 0.520 2003, 1, 3, 0,13.42, 0.539 ... (where day , is the day of the year ) and I'm trying to read them using the pandas library (seems a fantastic lib so far). There is a built-in function to read CSV in pandas, and even better, that function supposedly checks the columns for a date type. and automatically uses that as an index (which would be exactly perfect for what I'm doing). The thing is, I cannot get it to work with date data in this format. I

error 3 on dateutil/zoneinfo using cx_freeze and pandas

柔情痞子 提交于 2019-12-04 06:57:09
When I try to compile the hello.py file with cx_freeze, I get the following error with pandas 0.15.2 but no error with 0.15.1. Has someone any idea on how to correct it ? I have include the dateutil/zoneinfo files with the include_files function but the problem still occurs. hello.py: import numpy as np import pandas as pd import matplotlib import matplotlib.pyplot as plt print 'hello world' df_dates = pd.date_range(start='01/01/2013', freq='H', periods=100) df = pd.DataFrame(range(len(df_dates)), index=df_dates) print df print df.info() df.plot() plt.savefig('test.png') plt.show(block=False)

dateutil.parser.parse() and lost timezone information

微笑、不失礼 提交于 2019-12-04 06:23:33
I am trying to dateutil.parser.parse() to parse the default str(datetime.datetime.now()) output using timezone-aware datetimes. However, parse() seems to lose the timezone information and replace it with the local time timezone. Below is the IPython output: In [1]: from django.utils.timezone import now In [3]: import dateutil In [4]: t = now() In [6]: print t 2014-07-14 08:51:49.123342+00:00 In [7]: st = unicode(t) In [8]: print dateutil.parser.parse(st) 2014-07-14 08:51:49.123342+02:00 As far I understood dateutil does some heurestics when guessing the date format and it might go wrong here.

[python]It is a distutils installed project

北城以北 提交于 2019-12-04 03:46:41
sudo pip install pandas Installing collected packages: numpy, six, python-dateutil, pandas Found existing installation: numpy 1.8.0rc1 Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. You are using pip version 18.1, however version 19.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. sudo pip install --upgrade pip pip list|grep numpy numpy 1.8.0rc1 要求1.12版本,但是1.8版本 cd /System/Library/Frameworks/Python.framework/Versions/2.7

How to install the Six module in Python2.7

烂漫一生 提交于 2019-12-04 00:32:21
问题 I am using Python 2.7 and trying to use dateutil as follows: from dateutil import parser as _date_parser However, I get the following error: Traceback (most recent call last): File "<pyshell#17>", line 1, in <module> from dateutil import parser as _date_parser File "C:\Python27\Lib\dateutil\parser.py", line 24, in <module> from six import text_type, binary_type, integer_types ImportError: No module named six Could you please let me know what is the six module for and how to get it installed

Python cannot find dateutil.relativedelta

女生的网名这么多〃 提交于 2019-12-03 10:34:38
问题 I am trying to run a program using paster serve , but I keep getting the error: ImportError: No module named dateutil.relativedelta I am running Python version 2.6.7 and dateutil version 1.5, so it should be installed. Has anyone got any ideas as to why this would happen? I am importing using from dateutil.relativedelta import * I can even see the package when I search: /usr/lib/python2.7/site-packages/dateutil/relativedelta.pyc /usr/lib/python2.7/site-packages/dateutil/relativedelta.py /usr