網站首頁 編程語言 正文
準備工作(導入庫、導入數據)
import pandas as pd import matplotlib.pyplot as plt import numpy as np import seaborn as ?sns sns.set_style("darkgrid") ??
list_csv = ['Amazon_top_selling_book.csv','breast_cancer_wisconsin.csv','diamonds.csv','insurance.csv','netflix_titles.csv','penguins.csv', 'titanic.csv','winequality-red.csv'] dic_path = r'C:\Users\pandas\Desktop\task\228datasets\datasets' part_data = pd.read_csv(dic_path+'\\'+list_csv[4]) part_data
? | show_id | type | title | director | cast | country | date_added | release_year | rating | duration | listed_in | description |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | s1 | Movie | Dick Johnson Is Dead | Kirsten Johnson | NaN | United States | September 25, 2021 | 2020 | PG-13 | 90 min | Documentaries | As her father nears the end of his life, filmm... |
1 | s2 | TV Show | Blood & Water | NaN | Ama Qamata, Khosi Ngema, Gail Mabalane, Thaban... |
South Africa | September 24, 2021 | 2021 | TV-MA | 2 Seasons | International TV Shows, TV Dramas, TV Mysteries |
After crossing paths at a party, a Cape Town t... |
2 | s3 | TV Show | Ganglands | Julien Leclercq | Sami Bouajila, Tracy Gotoas, Samuel Jouy, Nabi... |
NaN | September 24, 2021 | 2021 | TV-MA | 1 Season | Crime TV Shows, International TV Shows, TV Act... |
To protect his family from a powerful drug lor... |
3 | s4 | TV Show | Jailbirds New Orleans | NaN | NaN | NaN | September 24, 2021 | 2021 | TV-MA | 1 Season | Docuseries, Reality TV | Feuds, flirtations and toilet talk go down amo... |
4 | s5 | TV Show | Kota Factory | NaN | Mayur More, Jitendra Kumar, Ranjan Raj, Alam K... |
India | September 24, 2021 | 2021 | TV-MA | 2 Seasons | International TV Shows, Romantic TV Shows, TV ... |
In a city of coaching centers known to train I... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8807 rows × 12 columns
檢測數據情況
Hint:該函數用于檢測任意DataFrame中缺失值情況
def missing_values_table(df): mis_val = df.isnull().sum() mis_val_percent = 100 * df.isnull().sum() / len(df) mis_val_table = pd.concat([mis_val, mis_val_percent], axis=1) mis_val_table_ren_columns = mis_val_table.rename( columns = {0 : 'Missing Values', 1 : '% of Total Values'}) mis_val_table_ren_columns = mis_val_table_ren_columns[ mis_val_table_ren_columns.iloc[:,1] != 0].sort_values( '% of Total Values', ascending=False).round(1) print ("Your selected dataframe has " + str(df.shape[1]) + " columns.\n" "There are " + str(mis_val_table_ren_columns.shape[0]) + " columns that have missing values.") return mis_val_table_ren_columns
missing_values_table(part_data)
Your selected dataframe has 12 columns.
There are 6 columns that have missing values.
? | Missing Values | % of Total Values |
---|---|---|
director | 2634 | 29.9 |
country | 831 | 9.4 |
cast | 825 | 9.4 |
date_added | 10 | 0.1 |
rating | 4 | 0.0 |
duration | 3 | 0.0 |
DataFrame.drop(labels=None,axis=0, index=None, columns=None, inplace=False)
參數說明:
- labels 就是要刪除的行列的名字,用列表給定
- axis 默認為0,指刪除行,因此刪除columns時要指定axis=1;
- index 直接指定要刪除的行
- columns 直接指定要刪除的列
- inplace=False,默認該刪除操作不改變原數據,而是返回一個執行刪除操作后的新dataframe;
- inplace=True,則會直接在原數據上進行刪除操作,刪除后無法返回。
方式一:刪除指定行或列
labels+axis
demo = part_data.drop(['director'], axis=1) missing_values_table(demo)
Your selected dataframe has 11 columns.
There are 5 columns that have missing values.
? | Missing Values | % of Total Values |
---|---|---|
country | 831 | 9.4 |
cast | 825 | 9.4 |
date_added | 10 | 0.1 |
rating | 4 | 0.0 |
duration | 3 | 0.0 |
方式二:利用boolean刪除滿足條件元素所在的行
df = df.drop(df[].index)
# 刪除release_year年份在2009年之前的行 demo = part_data.drop(part_data[part_data["release_year"]<2009].index) demo.shape
(7624, 12)
原文鏈接:https://blog.csdn.net/pylittlebrat/article/details/124505220
相關推薦
- 2022-05-25 Flutter實現掃二維碼功能_Android
- 2021-12-09 Linux環境下安裝JDK1.8_Linux
- 2024-02-28 UNI-APP中,swiper和tabbar結合實現滑動翻頁效果
- 2022-11-20 CPython?垃圾收集器檢測循環引用詳解_python
- 2022-10-20 kotlin淺析when與循環的使用_Android
- 2022-06-21 git基礎之各版本控制系統介紹_其它綜合
- 2022-05-13 FAILED: Execution Error, return code 1 from org.ap
- 2022-04-17 <el-dropdown>按鈕點擊出來下拉菜單,點擊下拉菜單觸發事件
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支