Skip to content

Commit 03dac2c

Browse files
committed
<add> : pd_calculate.py
- add pd_calculate script
1 parent 0062f91 commit 03dac2c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

PandasPractice/pd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@
9292
print('id of df2 :', id(df2))
9393

9494

95-
print(df == df2)?
95+

PandasPractice/pd_calculate.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pandas as pd
2+
3+
df = pd.DataFrame([[22,'남','덕영중'], [17,'여','수리중']], index=['학생1','학생2'], columns=['age','성별','학교'])
4+
df2 = df.rename(columns={'age': 'age', '성별': 'gender', '학교': 'school'})
5+
6+
7+
# eq compare
8+
'''
9+
print(df == df2) # ValueError: Can only compare identically-labeled (both index and columns) DataFrame objects
10+
print(df2 == df)
11+
'''
12+
13+
'''
14+
# drop column, row, inplace option 존재
15+
df.drop('학생1', inplace=True) # 기본 axis = 0
16+
print(df)
17+
df.drop(['성별'], axis=1, inplace=True)
18+
print(df)
19+
'''
20+
21+
# selecting data
22+
'''
23+
# selecting row
24+
label1 = df.loc['학생1'] # ['학생1':'학생101']
25+
label2 = df.loc['학생2']
26+
position1 = df.iloc[0] # [3:7]
27+
position2 = df.iloc[1]
28+
print(label1) # pandas.core.series.Series
29+
print(label2)
30+
print(position1) # pandas.core.series.Series
31+
print(position2)
32+
print(label1 == position1) # series끼리 eq연산을 해도 원소끼리 비교한다.
33+
'''
34+
35+
# selecting column
36+
col1 = df['학교']
37+
print(col1)

0 commit comments

Comments
 (0)