Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86723 > unrolled thread

date

Started bygreymausg <maus@mail.com>
First post2015-03-02 11:55 +0000
Last post2015-03-02 17:55 +0000
Articles 17 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  date greymausg <maus@mail.com> - 2015-03-02 11:55 +0000
    Re: date Fabien <fabien.maussion@gmail.com> - 2015-03-02 13:25 +0100
      Re: date Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 14:26 +0000
        Re: date Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 01:44 +1100
          Re: date Tim Golden <mail@timgolden.me.uk> - 2015-03-02 14:50 +0000
          Re: date Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 15:24 +0000
          Re: date Chris Angelico <rosuav@gmail.com> - 2015-03-03 02:51 +1100
            Re: date alister <alister.nospam.ware@ntlworld.com> - 2015-03-02 16:09 +0000
              Re: date Chris Angelico <rosuav@gmail.com> - 2015-03-03 03:25 +1100
              Re: date Dave Angel <davea@davea.name> - 2015-03-02 13:32 -0500
          Re: date Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 16:44 +0000
        Re: date Fabien <fabien.maussion@gmail.com> - 2015-03-02 16:42 +0100
          Re: date Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 16:41 +0000
      Re: date greymausg <maus@mail.com> - 2015-03-02 14:49 +0000
    Re: date Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 23:45 +1100
      Re: date greymausg <maus@mail.com> - 2015-03-02 14:49 +0000
        Re: date greymausg <maus@mail.com> - 2015-03-02 17:55 +0000

#86723 — date

Fromgreymausg <maus@mail.com>
Date2015-03-02 11:55 +0000
Subjectdate
Message-ID<slrnmf8hqo.6hg.maus@gmaus.info>
I have a csv file, the first item on a line is the date in the format
2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
replying "Expecting an integer". (I am really trying to get the offset
in weeks from that date to today())



-- 
greymaus
 .
  .
...

[toc] | [next] | [standalone]


#86726

FromFabien <fabien.maussion@gmail.com>
Date2015-03-02 13:25 +0100
Message-ID<md1ks9$epb$1@speranza.aioe.org>
In reply to#86723
On 02.03.2015 12:55, greymausg wrote:
> I have a csv file, the first item on a line is the date in the format
> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
> replying "Expecting an integer". (I am really trying to get the offset
> in weeks from that date to today())

Have you tried Pandas? http://pandas.pydata.org/

If your csv file has no other problems, the following should do the trick:

import pandas as pd
df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Cheers,

Fabien



[toc] | [prev] | [next] | [standalone]


#86737

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-02 14:26 +0000
Message-ID<mailman.40.1425306406.13471.python-list@python.org>
In reply to#86726
On 02/03/2015 12:25, Fabien wrote:
> On 02.03.2015 12:55, greymausg wrote:
>> I have a csv file, the first item on a line is the date in the format
>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>> replying "Expecting an integer". (I am really trying to get the offset
>> in weeks from that date to today())
>
> Have you tried Pandas? http://pandas.pydata.org/
>
> If your csv file has no other problems, the following should do the trick:
>
> import pandas as pd
> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})
>
> Cheers,
>
> Fabien
>

IMHO complete overkill.  Give me the Steven D'Aprano solution any day of 
the week.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#86742

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-03 01:44 +1100
Message-ID<54f47743$0$12979$c3e8da3$5496439d@news.astraweb.com>
In reply to#86737
Mark Lawrence wrote:

> Give me the Steven D'Aprano solution any day of
> the week.


Sounds ominous. Is that better or worse than the final solution?



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#86745

FromTim Golden <mail@timgolden.me.uk>
Date2015-03-02 14:50 +0000
Message-ID<mailman.43.1425307849.13471.python-list@python.org>
In reply to#86742
On 02/03/2015 14:44, Steven D'Aprano wrote:
> Mark Lawrence wrote:
> 
>> Give me the Steven D'Aprano solution any day of
>> the week.
> 
> 
> Sounds ominous. Is that better or worse than the final solution?
> 
> 
> 

Well if you can have it on any day of the week it can't be *that* final?

TJG

[toc] | [prev] | [next] | [standalone]


#86747

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-02 15:24 +0000
Message-ID<mailman.44.1425309910.13471.python-list@python.org>
In reply to#86742
On 02/03/2015 14:44, Steven D'Aprano wrote:
> Mark Lawrence wrote:
>
>> Give me the Steven D'Aprano solution any day of
>> the week.
>
>
> Sounds ominous. Is that better or worse than the final solution?
>

As in "this program will inadvertantly self distruct in five seconds"?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#86754

FromChris Angelico <rosuav@gmail.com>
Date2015-03-03 02:51 +1100
Message-ID<mailman.48.1425311498.13471.python-list@python.org>
In reply to#86742
On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> On 02/03/2015 14:44, Steven D'Aprano wrote:
>>
>> Mark Lawrence wrote:
>>
>>> Give me the Steven D'Aprano solution any day of
>>> the week.
>>
>>
>>
>> Sounds ominous. Is that better or worse than the final solution?
>>
>
> As in "this program will inadvertantly self distruct in five seconds"?

It's usually implied as being externally enforced, so I'd say it's
more akin to my solution to all manner of Windows problems.

ChrisA

[toc] | [prev] | [next] | [standalone]


#86757

Fromalister <alister.nospam.ware@ntlworld.com>
Date2015-03-02 16:09 +0000
Message-ID<md21vr$i9m$1@speranza.aioe.org>
In reply to#86754
On Tue, 03 Mar 2015 02:51:28 +1100, Chris Angelico wrote:

> On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence <breamoreboy@yahoo.co.uk>
> wrote:
>> On 02/03/2015 14:44, Steven D'Aprano wrote:
>>>
>>> Mark Lawrence wrote:
>>>
>>>> Give me the Steven D'Aprano solution any day of the week.
>>>
>>>
>>>
>>> Sounds ominous. Is that better or worse than the final solution?
>>>
>>>
>> As in "this program will inadvertantly self distruct in five seconds"?
> 
> It's usually implied as being externally enforced, so I'd say it's more
> akin to my solution to all manner of Windows problems.
> 
> ChrisA

Is that the same as my solution to windows related problems?

(Dad bought a new laptop on Sat it was sterilised (As in disinfected ) 
immediately & has never run Windowz - lucky thing).




-- 
Loose bits sink chips.

[toc] | [prev] | [next] | [standalone]


#86758

FromChris Angelico <rosuav@gmail.com>
Date2015-03-03 03:25 +1100
Message-ID<mailman.51.1425313525.13471.python-list@python.org>
In reply to#86757
On Tue, Mar 3, 2015 at 3:09 AM, alister
<alister.nospam.ware@ntlworld.com> wrote:
>>>> Sounds ominous. Is that better or worse than the final solution?
>>>>
>>>>
>>> As in "this program will inadvertantly self distruct in five seconds"?
>>
>> It's usually implied as being externally enforced, so I'd say it's more
>> akin to my solution to all manner of Windows problems.
>>
>> ChrisA
>
> Is that the same as my solution to windows related problems?
>
> (Dad bought a new laptop on Sat it was sterilised (As in disinfected )
> immediately & has never run Windowz - lucky thing).

Yes. What Steven is referencing is:

https://en.wikipedia.org/wiki/Final_Solution

And is unrelated to this:

https://en.wikipedia.org/wiki/Final_Problem

ChrisA

[toc] | [prev] | [next] | [standalone]


#86844

FromDave Angel <davea@davea.name>
Date2015-03-02 13:32 -0500
Message-ID<mailman.13.1425392617.21433.python-list@python.org>
In reply to#86757
On 03/02/2015 11:25 AM, Chris Angelico wrote:
> On Tue, Mar 3, 2015 at 3:09 AM, alister
> <alister.nospam.ware@ntlworld.com> wrote:
>>>>> Sounds ominous. Is that better or worse than the final solution?
>>>>>
>>>>>
>>>> As in "this program will inadvertantly self distruct in five seconds"?
>>>
>>> It's usually implied as being externally enforced, so I'd say it's more
>>> akin to my solution to all manner of Windows problems.
>>>
>>> ChrisA
>>
>> Is that the same as my solution to windows related problems?
>>
>> (Dad bought a new laptop on Sat it was sterilised (As in disinfected )
>> immediately & has never run Windowz - lucky thing).
>
> Yes. What Steven is referencing is:
>
> https://en.wikipedia.org/wiki/Final_Solution
>
> And is unrelated to this:
>
> https://en.wikipedia.org/wiki/Final_Problem
>
> ChrisA
>

And all of them unrelated to "The Last One"

http://en.wikipedia.org/wiki/The_Last_One_%28software%29

which was hyped to be the last program ever to be needed...

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#86761

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-02 16:44 +0000
Message-ID<mailman.54.1425314706.13471.python-list@python.org>
In reply to#86742
On 02/03/2015 15:51, Chris Angelico wrote:
> On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> On 02/03/2015 14:44, Steven D'Aprano wrote:
>>>
>>> Mark Lawrence wrote:
>>>
>>>> Give me the Steven D'Aprano solution any day of
>>>> the week.
>>>
>>>
>>>
>>> Sounds ominous. Is that better or worse than the final solution?
>>>
>>
>> As in "this program will inadvertantly self distruct in five seconds"?
>
> It's usually implied as being externally enforced, so I'd say it's
> more akin to my solution to all manner of Windows problems.
>
> ChrisA
>

Heard the joke about the three engineers in the car that breaks down?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#86751

FromFabien <fabien.maussion@gmail.com>
Date2015-03-02 16:42 +0100
Message-ID<md20cs$er0$1@speranza.aioe.org>
In reply to#86737
On 02.03.2015 15:26, Mark Lawrence wrote:
>>
>> Have you tried Pandas? http://pandas.pydata.org/
>>
>> If your csv file has no other problems, the following should do the
>> trick:
>>
>> import pandas as pd
>> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})
>>
>> Cheers,
>>
>> Fabien
>>
>
> IMHO complete overkill.  Give me the Steven D'Aprano solution any day of
> the week.

Without knowing anything about the OP background, I still hope my 
suggestion is a good one. Pandas is one of the best thing that happened 
to me in my python life, I'm happy to at least suggest it. But yeah, if 
you just want to read the csv and do no data crunching on it, pandas is 
"overkill".

Fabien

[toc] | [prev] | [next] | [standalone]


#86760

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-02 16:41 +0000
Message-ID<mailman.53.1425314529.13471.python-list@python.org>
In reply to#86751
On 02/03/2015 15:42, Fabien wrote:
> On 02.03.2015 15:26, Mark Lawrence wrote:
>>>
>>> Have you tried Pandas? http://pandas.pydata.org/
>>>
>>> If your csv file has no other problems, the following should do the
>>> trick:
>>>
>>> import pandas as pd
>>> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})
>>>
>>> Cheers,
>>>
>>> Fabien
>>>
>>
>> IMHO complete overkill.  Give me the Steven D'Aprano solution any day of
>> the week.
>
> Without knowing anything about the OP background, I still hope my
> suggestion is a good one. Pandas is one of the best thing that happened
> to me in my python life, I'm happy to at least suggest it. But yeah, if
> you just want to read the csv and do no data crunching on it, pandas is
> "overkill".
>
> Fabien

I've used pandas myself and I'll admit to being very impressed.  However 
the OP originally said 'I have a csv file, the first item on a line is 
the date in the format 2015-03-02 I try to get that as a date by 
date(row[0]), but it barfs, replying "Expecting an integer".'  Without 
finding out exactly what the OP is trying to achieve, telling them to 
download a package such as pandas just to convert a string to a date is 
overkill when there's a solution in the stdlib.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#86744

Fromgreymausg <maus@mail.com>
Date2015-03-02 14:49 +0000
Message-ID<slrnmf8rtl.7bj.maus@gmaus.info>
In reply to#86726
On 2015-03-02, Fabien <fabien.maussion@gmail.com> wrote:
> On 02.03.2015 12:55, greymausg wrote:
>> I have a csv file, the first item on a line is the date in the format
>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>> replying "Expecting an integer". (I am really trying to get the offset
>> in weeks from that date to today())
>
> Have you tried Pandas? http://pandas.pydata.org/
>
> If your csv file has no other problems, the following should do the trick:
>
> import pandas as pd
> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Ta. Will try

>
> Cheers,
>
> Fabien
>
>
>
>


-- 
greymaus
 .
  .
...

[toc] | [prev] | [next] | [standalone]


#86732

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-02 23:45 +1100
Message-ID<54f45b57$0$13004$c3e8da3$5496439d@news.astraweb.com>
In reply to#86723
greymausg wrote:

> I have a csv file, the first item on a line is the date in the format
> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
> replying "Expecting an integer". (I am really trying to get the offset
> in weeks from that date to today())

What is "date"? Where does it come from?

If it is your own function, then we cannot help you unless you show us the
code for it.

If you mean the standard library date, then you should say so.


py> from datetime import datetime
py> today = datetime.today()
py> astring = "2014-12-27"
py> another_day = datetime.strptime(astring, "%Y-%m-%d")
py> difference = today - another_day
py> difference.days
65
py> difference.days/7  # weeks
9.285714285714286


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#86743

Fromgreymausg <maus@mail.com>
Date2015-03-02 14:49 +0000
Message-ID<slrnmf8s58.7bj.maus@gmaus.info>
In reply to#86732
On 2015-03-02, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> greymausg wrote:
>
>> I have a csv file, the first item on a line is the date in the format
>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>> replying "Expecting an integer". (I am really trying to get the offset
>> in weeks from that date to today())
>
> What is "date"? Where does it come from?
>
> If it is your own function, then we cannot help you unless you show us the
> code for it.
>
> If you mean the standard library date, then you should say so.
>
>
> py> from datetime import datetime
> py> today = datetime.today()
> py> astring = "2014-12-27"
> py> another_day = datetime.strptime(astring, "%Y-%m-%d")
> py> difference = today - another_day
> py> difference.days
> 65
> py> difference.days/7  # weeks
> 9.285714285714286
>
>

Standard datetime.date, if it were not, I would have written.
Will try, thanks for the info.


-- 
greymaus
 .
  .
...

[toc] | [prev] | [next] | [standalone]


#86765

Fromgreymausg <maus@mail.com>
Date2015-03-02 17:55 +0000
Message-ID<slrnmf97bo.8ln.maus@gmaus.info>
In reply to#86743
On 2015-03-02, greymausg <maus@mail.com> wrote:
> On 2015-03-02, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
>> greymausg wrote:
>>
>>> I have a csv file, the first item on a line is the date in the format
>>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>>> replying "Expecting an integer". (I am really trying to get the offset
>>> in weeks from that date to today())
>>
>> What is "date"? Where does it come from?
>>
>> If it is your own function, then we cannot help you unless you show us the
>> code for it.
>>
>> If you mean the standard library date, then you should say so.
>>
>>
>> py> from datetime import datetime
>> py> today = datetime.today()
>> py> astring = "2014-12-27"
>> py> another_day = datetime.strptime(astring, "%Y-%m-%d")
>> py> difference = today - another_day
>> py> difference.days
>> 65
>> py> difference.days/7  # weeks
>> 9.285714285714286
>>
>>
>
> Standard datetime.date, if it were not, I would have written.
> Will try, thanks for the info.
>
>

Thanks to all, the strptime did the trick, after I realized
that I was comparing a 2digit year to a 4digit.


-- 
greymaus
 .
  .
...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web