PYTHON 프로그래밍

본문 바로가기
사이트 내 전체검색


PYTHON 프로그래밍
PYTHON 프로그래밍

4. Pandas 연산

페이지 정보

작성자 관리자 댓글 0건 조회 3,771회 작성일 19-10-01 08:12

본문

4. Pandas 연산

# -*- coding: utf-8 -*-

import pandas as pd
df = pd.DataFrame({'col1':[1,2,3,4],'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})
print(df)
df.head()

 

# unique


print("\n=====================")
obj = df['col2'].unique()
print(obj)

print("\n=====================")
obj = df['col2'].nunique() # number unique
print(obj)

print("\n=====================")
obj = df['col2'].value_counts() # 값이 몇번나오는가
print(obj)

 

# 데이타 값으로 선택


print("\n=====================")
obj = df[(df['col1']>2) & (df['col2']==444)]
print(obj)

 

   col1  col2 col3
0     1   444  abc
1     2   555  def
2     3   666  ghi
3     4   444  xyz

=====================
[444 555 666]

=====================
3

=====================
444    2
555    1
666    1
Name: col2, dtype: int64

=====================
   col1  col2 col3
3     4   444  xyz
계속하려면 아무 키나 누르십시오 . . .

 

참고사이트 :

# https://www.youtube.com/watch?v=hZ4qvaj44-0

# http://www.thinkalgo.co.kr/detail.php?number=152&category=1018

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.