Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- DataFrame
- len()
- nan
- insert()
- elbow method
- list
- count()
- pandas
- 분류 결과표
- 반복문
- hierarchical_clustering
- 최솟값
- Machine Learning
- numpy
- string
- IN
- DataAccess
- analizer
- matplotlib
- 덴드로그램
- wcss
- del
- function
- sklearn
- Dictionary
- append()
- Python
- 최댓값
- data
- dendrogram
Archives
- Today
- Total
개발공부
Pandas Series 의 dt 속성 사용법 본문
df 속성을 이용하면 datetime 형식의 데이터에서 각 년, 월, 일, 시, 분, 초 등 원하는
기준으로 데이터를 읽어낼 수 있다.
import pandas as pd
dates = ['2012-02-04 09:10:00', '2017-07-07 14:10:00', '2019-11-08 15:20:10', '2021-12-22 22:15:30']
dates = pd.to_datetime(dates)
df = pd.DataFrame(data = {'Date' : dates})
df

# 날짜 전체 읽기
>>> df['Date'].dt.date
0 2012-02-04
1 2017-07-07
2 2019-11-08
3 2021-12-22
Name: Date, dtype: object
# 년만 읽기
>>> df['Date'].dt.year
0 2012
1 2017
2 2019
3 2021
Name: Date, dtype: int64
# 월만 읽기
>>> df['Date'].dt.month
0 2
1 7
2 11
3 12
Name: Date, dtype: int64
# 월의 이름 읽기
>>> df['Date'].dt.month_name()
0 February
1 July
2 November
3 December
Name: Date, dtype: object
# 일 읽기
>>> df['Date'].dt.day
0 4
1 7
2 8
3 22
Name: Date, dtype: int64
# 시간 읽기
>>> df['Date'].dt.time
0 09:10:00
1 14:10:00
2 15:20:10
3 22:15:30
Name: Date, dtype: object
# 시 읽기
>>> df['Date'].dt.hour
0 9
1 14
2 15
3 22
Name: Date, dtype: int64
# 분 읽기
>>> df['Date'].dt.minute
0 10
1 10
2 20
3 15
Name: Date, dtype: int64
# 초 읽기
>>> df['Date'].dt.second
0 0
1 0
2 10
3 30
Name: Date, dtype: int64'Python > Pandas' 카테고리의 다른 글
| Time Series 데이터를 처리할 때 사용하는 resample 함수 (0) | 2022.05.13 |
|---|---|
| pandas.read_csv 함수의 error_bad_lines=False 파라미터 사용법 (0) | 2022.05.12 |
| [Python] Pandas 에서 시간 처리 [생성(datetimeIndex() , to_datetime()), 연산, 인덱싱] (0) | 2022.05.06 |
| [Python] Pandas pivot_table() 생성하기 (0) | 2022.05.04 |
| [Python] Pandas Dataframe 합치기 concat(), merge() (0) | 2022.05.03 |