# 데이터프레임 열 삭제
print(scientists.columns)

scientists_dropped = scientists.drop(['Age'], axis=1)

print(scientists_dropped.columns)​
import pandas as pd

scientists = pd.read_csv('./data/scientists.csv')

print(scientists)
# 불린 추출
print(scientists[scientists['Age'] > scientists['Age'].mean()])

print(scientists['Age'] > scientists['Age'].mean())

print(scientists.loc[[True, True, False, True]])

# 브로드캐스팅 (정수는 2를 곱함, 문자열은 2배로 늘어남)
print(scientists * 2)
# 데이터형식 조회
print(scientists['Born'].dtype)
print(scientists['Died'].dtype)

# 데이터형식 변경
born_datetime = pd.to_datetime(scientists['Born'], format='%Y-%m-%d')
print(born_datetime)

died_datetime = pd.to_datetime(scientists['Died'], format='%Y-%m-%d')
print(died_datetime)

# 기존 데이터프레임에 열추가
scientists['born_dt'], scientists['died_dt'] = (born_datetime, died_datetime)
print(scientists.head())

scientists['age_days_dt'] = (scientists['died_dt'] - scientists['born_dt'])
print(scientists)

# 랜덤
import random

print(scientists['Age'])
 
random.seed(42)
random.shuffle(scientists['Age'])

print(scientists['Age'])
 
# 데이터프레임 열 삭제
print(scientists.columns)

scientists_dropped = scientists.drop(['Age'], axis=1)

print(scientists_dropped.columns)

+ Recent posts