pandas处理丢失数据 None与np.nan
有两种丢失数据:
-
None
-
np.nan(NaN)
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
df = pd.read_excel(‘students.xlsx’)
df
------------------------------
name age python java c
0 lucy 19.0 90 90.0 90
1 mery NaN 98 89.0 100
2 tom 19.0 89 NaN 95
3 jack 20.0 100 98.0 100
df.dtypes
------------------------------
name object
age float64
python int64
java float64
c int64
dtype: object
type(df.loc[1,"age"])
-----------------------
numpy.float64
# 1. pandas业务表处理的,需要进行运算 np.nan
# 2. object运算效率远低于float类型
- None
None是Python自带的,其类型为python object。因此,None不能参与到任何计算中。
object类型的运算要比int类型的运算慢得多
计算不同数据类型求和时间
%timeit np.arange(1e5,dtype=xxx).sum()
df = DataFrame(data=np.random.randint(0,10