728x90
In [11]:
# date: define dates only without including time (month, day, year)
# datetime : define times and dates together (month, day, year, hour, second, microsecond)
import pandas as pd
import datetime as dt
In [12]:
# A date
date_ex = dt.date(2022,1,1)
date_ex
Out[12]:
datetime.date(2022, 1, 1)
In [13]:
type(date_ex)
Out[13]:
datetime.date
In [14]:
# Convert it into string to view
str(now)
Out[14]:
'2022-01-01'
In [15]:
date_ex.day
Out[15]:
1
In [16]:
date_ex.month
Out[16]:
1
In [17]:
datetime_ex = dt.datetime(2022, 3, 31, 9,30, 50)
In [18]:
str(datetime_ex)
Out[18]:
'2022-03-31 09:30:50'
In [19]:
datetime_ex.hour
Out[19]:
9
In [20]:
datetime_ex.minute
Out[20]:
30
In [22]:
import calendar
print(calendar.month(2023, 1))
January 2023
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
In [24]:
dates = pd.Series(['2020/03/22','2020-08-25','March 22nd, 2020'])
dates
Out[24]:
0 2020/03/22
1 2020-08-25
2 March 22nd, 2020
dtype: object
In [25]:
# string format to a datetime object
dates_convert = pd.to_datetime(dates)
dates_convert
Out[25]:
0 2020-03-22
1 2020-08-25
2 2020-03-22
dtype: datetime64[ns]
728x90
'Data Analytics with python > [Data Analysis]' 카테고리의 다른 글
[datetime]S7_03_Practical_example1 (0) | 2023.01.21 |
---|---|
[datetime]S7_02_Timestamp (0) | 2023.01.21 |
[seaborn]S6_02_pairplot,displot,heatmap(correlations) (0) | 2023.01.21 |
[seaborn]S6_01_scatter&count_plot (0) | 2023.01.21 |
[matplotlib]S5_appendix_Making_dataset(주식 일별 수익률 계산) (0) | 2023.01.21 |
댓글