Python Forum
Convert SAS Dates Format in a loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert SAS Dates Format in a loop
#3
Try something like this instead:

def convert_sas_dates(df, field, inplace=False, unit='s'):
    """Converts sas-formated column to standard.
    """
    if inplace:
        df.loc[:, field] = pd.to_timedelta(df.loc[:, field]) + pd.datetime(1960, 1, 1)
    else:
        df_ = df.copy()
        df_.loc[:, field] = pd.to_timedelta(df_.loc[:, field], unit=unit) + pd.datetime(1960,1,1)
        return df_
Reply


Messages In This Thread
Convert SAS Dates Format in a loop - by MohanReddy - Apr-01-2019, 04:56 AM
RE: Convert SAS Dates Format in a loop - by scidam - Apr-02-2019, 10:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  loop through csv format from weburl in python maddyad82 3 434 Jan-17-2024, 10:08 PM
Last Post: deanhystad
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 780 Sep-22-2023, 02:33 PM
Last Post: carecavoador
  convert this List Comprehensions to loop jacklee26 8 1,540 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  Convert Json to table format python_student 2 5,657 Sep-28-2022, 12:48 PM
Last Post: python_student
  Convert .xlsx to Format as Table bnadir55 0 909 Aug-11-2022, 06:39 AM
Last Post: bnadir55
  how to convert and format a varable darktitan 4 1,719 May-29-2022, 12:59 PM
Last Post: darktitan
  Convert Date to another format lonesoac0 2 1,685 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Convert timedelta to specified format Planetary_Assault_Systems 3 3,231 Jun-27-2021, 01:46 PM
Last Post: snippsat
  How to convert dates in odd format to months lokhtar 2 2,258 Apr-17-2021, 11:54 AM
Last Post: lokhtar
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,269 Mar-11-2021, 10:52 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020