iT邦幫忙

2022 iThome 鐵人賽

DAY 24
0
AI & Data

了解Data Science系列 第 24

Python pandas part 5

  • 分享至 

  • xImage
  •  

一樣用這dataframe

import pandas as pd
import numpy as np
data ={'name':['Kevin', 'Jimmy', 'Jame','Ken','Jenny'],
    'email':['abc@gmail.com', 'def@gmail.com', 'ghi@gmail.com', 'jkl@gmail.com','mn@gmail.com'],
    'salary':[41000, 39000, 53000, 62000,np.nan]}
employee_df = pd.DataFrame(data)
print(employee_df)

output
https://ithelp.ithome.com.tw/upload/images/20221010/20151606stgoJEVavg.png

處理空值

employee_df=employee_df.fillna(0) #設空值為0
print(employee_df)

output
https://ithelp.ithome.com.tw/upload/images/20221010/20151606QL8OrL5H3V.png

employee_df=employee_df.fillna("Unknown") #設空值為Unknown
print(employee_df)
ouput
https://ithelp.ithome.com.tw/upload/images/20221010/20151606SuziD9z6zk.png

欄位條件

filt=employee_df['salary']>45000 #找出salary大於45000
print(employee_df.loc[filt])

https://ithelp.ithome.com.tw/upload/images/20221010/20151606b7t2ZHcJaw.png


上一篇
Python pandas part 4
下一篇
Python pandas part 6
系列文
了解Data Science30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言