User Tools

Site Tools


convert_string_to_date

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
convert_string_to_date [2022/11/28 04:48] – [multiple dates; using pandas] rajuconvert_string_to_date [2022/11/28 04:59] – [single date string; without pandas; to datetime.date] raju
Line 1: Line 1:
-==== single date; without pandas; to datetime.date ====+==== single date string; without pandas; to datetime.date ====
 Use <code> Use <code>
 from datetime import datetime from datetime import datetime
Line 26: Line 26:
 </code> </code>
  
-==== multiple dates in a series; using pandas ====+Ref:- 
 +  * https://stackoverflow.com/questions/9504356/convert-string-into-date-type-on-python - where I found the answer 
 +  * https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes - shows the list of all the format codes such as %B, %Y. 
 + 
 +==== series of date strings; using pandas ====
 use <code> use <code>
 df[col_name] = pd.to_datetime(df[col_name], format_str) df[col_name] = pd.to_datetime(df[col_name], format_str)
Line 75: Line 79:
 dtype: object dtype: object
 </code> </code>
 +
 +See also: https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html
 +
convert_string_to_date.txt · Last modified: 2022/11/28 05:00 by raju