BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sastpw
SAS Employee

Good deal, glad that got you going. Yes, good job on the second one. I think even just doing mydata['Col2'] =  str(mydata['Col2']) would work too; str() of about anything gives you the string representation. But, there's a lot of different ways to accomplish something in python, so whatever works.

 

For the first column, I'm no pandas expert, so I had to play with this and figure it out. I found a case that worked. Again, could be lots of ways to do this kind of thing. Here's what I found:

 

>>> pd.to_datetime('20NOV2007:00:00:00', format='%d%b%Y:%H:%M:%S')
Timestamp('2007-11-20 00:00:00')

 

The doc for pandas.to_datetime is here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html

and under the format= parm it points to the formatting codes to use: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

 

See if that solves this for you.

Tom

 

>>> df
a
0 20NOV2007:00:00:00
>>> df.ftypes
a object:dense
dtype: object

 

>>> df['a'] = pd.to_datetime(df['a'], format='%d%b%Y:%H:%M:%S')
>>> df
a
0 2007-11-20
>>> df.dtypes
a datetime64[ns]
dtype: object
>>>

AshishM
Fluorite | Level 6

Hi Tom,

Thanks a lot for all your help and guidance.  I went through your original post again and came up with the same approach. I referred to the same link to come to up with the same solution :). I am new to Pandas, SAS and python so learning them slowly and spending a lot of time to solve issues.

I am now stuck with another issue, will try my best to fix it if not then I'll post it again.

 

Thanks again for your time. Much appreciated.

Ashish

sastpw
SAS Employee

That's tough trying to learn all 3 at the same time. Good job for doing so!

Here are a few links that I always have open, beyond just googling things, that I've found to be very helpful as I've taught myself Python. You can look at whatever version you like:

https://docs.python.org/3.5/index.html  has 2 links that I use the most:

https://docs.python.org/3.5/library/index.html   

https://docs.python.org/3.5/reference/index.html

 

And for Pandas, specifically: https://pandas.pydata.org/pandas-docs/stable/index.html

The API reference is key: https://pandas.pydata.org/pandas-docs/stable/reference/index.html

 

And don't forget SAS, it has more tricks than the other two:

https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=pgmsashome&docsetTarge...

 

Hopefully these references will help you along your journey; they have for me.

 

Tom

 

AshishM
Fluorite | Level 6

Awesome!!! thanks exactly what I would need as a beginner. Have bookmarked all of them.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 12559 views
  • 6 likes
  • 3 in conversation