新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python3.5Pandas模塊缺失值處理和層次索引實(shí)例詳解-創(chuàng)新互聯(lián)
本文實(shí)例講述了Python3.5 Pandas模塊缺失值處理和層次索引。分享給大家供大家參考,具體如下:

1、pandas缺失值處理



import numpy as np
import pandas as pd
from pandas import Series,DataFrame
df3 = DataFrame([
["Tom",np.nan,456.67,"M"],
["Merry",34,345.56,np.nan],
[np.nan,np.nan,np.nan,np.nan],
["John",23,np.nan,"M"],
["Joe",18,385.12,"F"]
],columns = ["name","age","salary","gender"])
print(df3)
print("=======判斷NaN值=======")
print(df3.isnull())
print("=======判斷非NaN值=======")
print(df3.notnull())
print("=======刪除包含NaN值的行=======")
print(df3.dropna())
print("=======刪除全部為NaN值的行=======")
print(df3.dropna(how="all"))
df3.ix[2,0] = "Gerry" #修改第2行第0列的值
print(df3)
print("=======刪除包含NaN值的列=======")
print(df3.dropna(axis=1))
分享題目:Python3.5Pandas模塊缺失值處理和層次索引實(shí)例詳解-創(chuàng)新互聯(lián)
文章鏈接:http://www.dlmjj.cn/article/jdepd.html


咨詢
建站咨詢
