!pip install pandas
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (1.5.3)
Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2022.7.1)
Requirement already satisfied: numpy>=1.21.0 in /usr/local/lib/python3.10/dist-packages (from pandas) (1.22.4)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)
import pandas as pd
data1 = [[67, 93, 91],
[65, 90, 80],
[89, 61, 13],
[83, 66, 45],
[77, 96, 57]]
idx1 = ['김사과', '반하나', '오렌지', '이메론', '배애리']
col1 = ['국어', '영어', '수학']
df.head()
df['blood'] # 데이터 타입은 series이다. 하나의 컬럼에 순서가 매겨졌고 값이 매칭.Series이다.
0 A
1 A
2 A
3 AB
4 A
5 A
6 O
7 B
8 O
9 A
10 A
11 B
12 AB
13 O
14 O
Name: blood, dtype: object
type(df['blood'])
pandas.core.series.Series
df.blood
0 A
1 A
2 A
3 AB
4 A
5 A
6 O
7 B
8 O
9 A
10 A
11 B
12 AB
13 O
14 O
Name: blood, dtype: object
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 15 entries, 0 to 14
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 15 non-null object
1 group 14 non-null object
2 company 15 non-null object
3 gender 15 non-null object
4 birthday 15 non-null object
5 height 13 non-null float64
6 blood 15 non-null object
7 brand 15 non-null int64
dtypes: float64(1), int64(1), object(6)
memory usage: 1.1+ KB
df['생년월일'].dt.month
0 10
1 8
2 12
3 12
4 7
5 9
6 8
7 8
8 12
9 3
10 3
11 3
12 7
13 6
14 3
15 1
Name: 생년월일, dtype: int64
df['생년월일'].dt.day
0 13
1 18
2 10
3 30
4 23
5 1
6 9
7 26
8 4
9 22
10 9
11 30
12 21
13 8
14 9
15 1
Name: 생년월일, dtype: int64
df['생년월일'].dt.time
0 00:00:00
1 00:00:00
2 00:00:00
3 00:00:00
4 00:00:00
5 00:00:00
6 00:00:00
7 00:00:00
8 00:00:00
9 00:00:00
10 00:00:00
11 00:00:00
12 00:00:00
13 00:00:00
14 00:00:00
15 00:00:00
Name: 생년월일, dtype: object
df['생년월일'].dt.hour
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
Name: 생년월일, dtype: int64
df['생년월일'].dt.second
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
Name: 생년월일, dtype: int64
df['생년월일'].dt.dayofweek # 요일: 0(월요일) ~ 6(일요일)
0 4
1 3
2 1
3 5
4 6
5 0
6 2
7 2
8 4
9 1
10 3
11 6
12 4
13 3
14 1
15 5
Name: 생년월일, dtype: int64
df['생년월일'].dt.isocalendar().week # 몇 번째 주인지 뽑을 수 있음
0 41
1 33
2 50
3 52
4 29
5 36
6 32
7 35
8 49
9 12
10 10
11 13
12 29
13 23
14 10
15 52
Name: week, dtype: UInt32
0 1
1 1
2 1
3 1
4 0
5 1
6 1
7 0
8 1
9 1
10 0
11 1
12 1
13 1
14 1
Name: 성별, dtype: int64
df['성별'].apply(lambda x: 1 if x == '남자' else 0) # 함수는 한번쓰고 버릴거라 람다를 사용
0 1
1 1
2 1
3 1
4 0
5 1
6 1
7 0
8 1
9 1
10 0
11 1
12 1
13 1
14 1
Name: 성별, dtype: int64