df.groupby된 정보는 object에 불과함


Out[17]:
<pandas.core.groupby.groupby.DataFrameGroupBy object at 0x0000028890B2D710>
In [19]:
('devils',     Teams  Rank  Year  Points
2  devils     2    14     136
3  devils     3    15     123)
('kings',    Teams  Rank  Year  Points
4  kings     3    14     878
5  kings     4    15     533
6  kings     1    16     234
7  kings     1    17     345)
('riders',      Teams  Rank  Year  Points
0   riders     1    14     845
1   riders     2    15     734
8   riders     2    16     745
11  riders     2    17     463)
('royals',      Teams  Rank  Year  Points
9   royals     4    14     113
10  royals     1    15     345)










df.groupby(["column1", "column2"])["data"].연산함수()

➡컬럼1과 컬럼2를 기준으로 컬럼을 그룹화 시킨다음에, 그 안에 들어가는 실질적인 데이터는 data에 연산함수 적용한걸 넣을거야








Out[17]:
<pandas.core.groupby.groupby.DataFrameGroupBy object at 0x0000028890B2D710>
In [19]:
('devils',     Teams  Rank  Year  Points
2  devils     2    14     136
3  devils     3    15     123)
('kings',    Teams  Rank  Year  Points
4  kings     3    14     878
5  kings     4    15     533
6  kings     1    16     234
7  kings     1    17     345)
('riders',      Teams  Rank  Year  Points
0   riders     1    14     845
1   riders     2    15     734
8   riders     2    16     745
11  riders     2    17     463)
('royals',      Teams  Rank  Year  Points
9   royals     4    14     113 

10 royals 1 15 345)






































*lambda 내의 if문


a = 2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# positive

a = -2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# negative

a = 0
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# zero


https://note.nkmk.me/python-if-conditional-expressions/














*dataframe값에 values 함수를 활용하면 numpy값으로 변환해준다.


Out[8]:
array([['jason', 'miller', 42, 'sanfran'],
       ['molly', 'jacobson', 62, 'la'],
       ['tina', 'ali', 12, 'san jose'],
       ['jake', 'milner', 53, 'san diego'],
       ['ally', 'cooze', 23, 'las vegas']], dtype=object)


















+ Recent posts