Python_48_ 데이터분석

hyeong taek jo·2023년 9월 20일

Python

목록 보기
52/53

📌info()

# 기본정보 보여주기  data frame structure using the .info() method
print(marathon_2017.info())

Column Non-Null Count Dtype
--- ------ -------------- -----
0 Unnamed: 0 26410 non-null int64
1 Bib 26410 non-null object
2 Name 26410 non-null object
3 Age 26410 non-null int64
4 M/F 26410 non-null object
5 City 26410 non-null object


📌drop()

  • Null Data 및 불 필요 필드 정리
import pandas as pd
# Load the CSV file "marathon_results_2017.csv" under "data" folder
marathon_2017 = pd.read_csv('../data/marathon_results_2017.csv')

#Drop some columns with null values
# Null Data 및 불 필요 필드 정리 -> marathon_2017_clean
marathon_2017_clean = marathon_2017.drop(['Unnamed: 0','Bib','Unnamed: 9'],axis='columns')

# Select Name
names = marathon_2017_clean.Name
#Display names
print("-------------------marathon_2017_clean.Name--------------")
print(names)

📌컬럼에 수식 넣기

# Import pandas as a alias 'pd'
import pandas as pd
# Load the CSV file "marathon_results_2017.csv" under "data" folder
marathon_2017 = pd.read_csv("../data/marathon_results_2017.csv")

#Drop some columns with null values
# Null Data 및 불 필요 필드 정리 -> marathon_2017_clean
marathon_2017_clean = marathon_2017.drop(['Unnamed: 0','Bib','Unnamed: 9'], axis='columns')

print("----------marathon_2017_clean------------")
print(marathon_2017_clean)

print("----------marathon_2017_clean.info()------------")
print(marathon_2017_clean.info())

# Age 50이상인 분들
#seniors = marathon_2017_clean.Age > 50     #이렇게 하면 Age에 컬럼만 나온다.
seniors = marathon_2017_clean[marathon_2017_clean.Age > 50] # 이렇게하면 필터를 거치고 다나옴

#Display seniors
print("---------Age 50이상인 분들 ------------")
print(seniors)

# kenna 국적 사람 선택
KEN_runner = marathon_2017_clean[marathon_2017_clean.Country == 'KEN']
#KEN_runner = marathon_2017_clean.Country == 'KEN'

#Display runners from kennay
print("-----------KEN_runner------------")
print(KEN_runner)

📌 컬럼추가

# Import pandas as a alias 'pd'
import pandas as pd
# Load the CSV file "marathon_results_2017.csv" under "data" folder
marathon_2017 = pd.read_csv("../data/marathon_results_2017.csv")

#Drop some columns with null values
# Null Data 및 불 필요 필드 정리 -> marathon_2017_clean
marathon_2017_clean = marathon_2017.drop(['Unnamed: 0','Bib','Unnamed: 9'], axis='columns')

print("----------marathon_2017_clean------------")
print(marathon_2017_clean)

print("----------marathon_2017_clean.info()------------")
print(marathon_2017_clean.info())

# Add Senior column with boolean value whether age is more than 60 or not
marathon_2017_clean['Senior'] = marathon_2017_clean.Age > 60

# Display updated data frame with .head() method
print(marathon_2017_clean.head())

# Year column 추가  Year <-- 2017
marathon_2017_clean['Year'] = '2017'

# Display updated data frame with .head() method
print(marathon_2017_clean.head())

profile
마포구 주민

0개의 댓글