datestr2num for day/month/year

Hello List,

datestr2num works great when dates are stored as month/day/year (as American like).

Europeans store them as day/month/year.

Any quick function to convert a day/month/year string do a date? Is there an eu version: datestr2numeu?

Thanks,

Mark

OK, I figured out I can use:
converters={0:strpdate2num(’%d-%m-%y’)}

What now if part of my dates are given as ‘day-month-year’ and part as ‘day/month/year’ in the same file (I know, who does that, an I could do a replace first and then read it in). Can I specify both formats for the converter? I guess not…

Thanks,

Mark

···

On Fri, Apr 25, 2014 at 10:46 AM, Mark Bakker <markbak@…287…> wrote:

Hello List,

datestr2num works great when dates are stored as month/day/year (as American like).

Europeans store them as day/month/year.

Any quick function to convert a day/month/year string do a date? Is there an eu version: datestr2numeu?

Thanks,

Mark

OK, I figured out I can use:
converters={0:strpdate2num('%d-%m-%y')}

What now if part of my dates are given as 'day-month-year' and part as
'day/month/year' in the same file (I know, who does that, an I could do
a replace first and then read it in). Can I specify both formats for the
converter? I guess not....

Try this:

   def _conv_date(s):
       try:
           return strpdate2num('%d-%m-%y')
       except Exception: # figure out which exception class to use
           return strpdate2num('%d/%m/%y')

   converters={0:_conv_date}

Cheers, Andreas.

···

On 25.04.2014 11:02, Mark Bakker wrote:

Thanks,

Mark

On Fri, Apr 25, 2014 at 10:46 AM, Mark Bakker <markbak@…287… > <mailto:markbak@…287…>> wrote:

    Hello List,

    datestr2num works great when dates are stored as month/day/year (as
    American like).

    Europeans store them as day/month/year.

    Any quick function to convert a day/month/year string do a date? Is
    there an eu version: datestr2numeu?

    Thanks,

    Mark

------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
-- Andreas.

Thanks, Andreas, but it doesn’t quite work.

This works for me (I manually changed all dates to ‘day-month-year’ for testing):

a = loadtxt(‘test.csv’,converters={2:strpdate2num(’%d-%m-%Y’)})

But when I define the same function in a separate function, as you suggested:

def conv_date(s):

return strpdate2num(’%d-%m-%Y’)

and do

a = loadtxt(‘test.csv’,converters={2:conv_date})

I get the non-descript error:

loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)

847 fh.close()

848

–> 849 X = np.array(X, dtype)

850 # Multicolumn data are returned with shape (1, N, M), i.e.

851 # (1, 1, M) for a single row - remove the singleton dimension there

SystemError: error return without exception set

Any suggestions?

Thanks, Mark

···

On Fri, Apr 25, 2014 at 11:17 AM, Andreas Hilboll <lists@…3067…> wrote:

On 25.04.2014 11:02, Mark Bakker wrote:

OK, I figured out I can use:

converters={0:strpdate2num(’%d-%m-%y’)}

What now if part of my dates are given as ‘day-month-year’ and part as

‘day/month/year’ in the same file (I know, who does that, an I could do

a replace first and then read it in). Can I specify both formats for the

converter? I guess not…

Try this:

def _conv_date(s):

   try:

       return strpdate2num('%d-%m-%y')

   except Exception:   # figure out which exception class to use

       return strpdate2num('%d/%m/%y')

converters={0:_conv_date}

Cheers, Andreas.

Thanks,

Mark

On Fri, Apr 25, 2014 at 10:46 AM, Mark Bakker <markbak@…287…

mailto:markbak@...287...> wrote:

Hello List,
datestr2num works great when dates are stored as month/day/year (as
American like).
Europeans store them as day/month/year.
Any quick function to convert a day/month/year string do a date? Is
there an eu version: datestr2numeu?
Thanks,
Mark

Start Your Social Network Today - Download eXo Platform

Build your Enterprise Intranet with eXo Platform Software

Java Based Open Source Intranet - Social, Extensible, Cloud Ready

Get Started Now And Turn Your Intranet Into A Collaboration Platform

http://p.sf.net/sfu/ExoPlatform


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

– Andreas.

You might have more luck reading in that data (dates with mixed format) with pandas than numpy.

···

On Fri, Apr 25, 2014 at 2:37 AM, Mark Bakker <markbak@…287…> wrote:

Thanks, Andreas, but it doesn’t quite work.

This works for me (I manually changed all dates to ‘day-month-year’ for testing):

a = loadtxt(‘test.csv’,converters={2:strpdate2num(’%d-%m-%Y’)})

But when I define the same function in a separate function, as you suggested:

def conv_date(s):

return strpdate2num(’%d-%m-%Y’)

and do

a = loadtxt(‘test.csv’,converters={2:conv_date})

I get the non-descript error:

loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)

847 fh.close()

848

–> 849 X = np.array(X, dtype)

850 # Multicolumn data are returned with shape (1, N, M), i.e.

851 # (1, 1, M) for a single row - remove the singleton dimension there

SystemError: error return without exception set

Any suggestions?

Thanks, Mark


Start Your Social Network Today - Download eXo Platform

Build your Enterprise Intranet with eXo Platform Software

Java Based Open Source Intranet - Social, Extensible, Cloud Ready

Get Started Now And Turn Your Intranet Into A Collaboration Platform

http://p.sf.net/sfu/ExoPlatform


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

On Fri, Apr 25, 2014 at 11:17 AM, Andreas Hilboll <lists@…3067…> wrote:

On 25.04.2014 11:02, Mark Bakker wrote:

OK, I figured out I can use:

converters={0:strpdate2num(’%d-%m-%y’)}

What now if part of my dates are given as ‘day-month-year’ and part as

‘day/month/year’ in the same file (I know, who does that, an I could do

a replace first and then read it in). Can I specify both formats for the

converter? I guess not…

Try this:

def _conv_date(s):

   try:

       return strpdate2num('%d-%m-%y')

   except Exception:   # figure out which exception class to use

       return strpdate2num('%d/%m/%y')

converters={0:_conv_date}

Cheers, Andreas.

Thanks,

Mark

On Fri, Apr 25, 2014 at 10:46 AM, Mark Bakker <markbak@…287…

mailto:markbak@...287...> wrote:

Hello List,
datestr2num works great when dates are stored as month/day/year (as
American like).
Europeans store them as day/month/year.
Any quick function to convert a day/month/year string do a date? Is
there an eu version: datestr2numeu?
Thanks,
Mark

Start Your Social Network Today - Download eXo Platform

Build your Enterprise Intranet with eXo Platform Software

Java Based Open Source Intranet - Social, Extensible, Cloud Ready

Get Started Now And Turn Your Intranet Into A Collaboration Platform

http://p.sf.net/sfu/ExoPlatform


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

– Andreas.