python笔记:3.2.2.9pandas数据操作_缺失值之缺失数据插值

# -*- coding: utf-8 -*-
"""
Created on Fri May 24 23:22:02 2019

@author: User
"""

import pandas as pd
import numpy as np

scoresheet=pd.DataFrame({'Name':['Christoph','Morgan','Michel','Jones'],
                         'Economics':[89,97,56,82],
                         'Statistics':[98,93,76,85]})

scoresheet['Datamining']=[79,np.nan,None,89]
scoresheet.loc[[1,3],['Name']]=[np.nan,None]
scoresheet['Exam_Date']=pd.date_range('20170707',periods=4)

print("\n 13-----------------------:")
scoresheet.loc[[2,3],['Exam_Date']]=np.nan
print(scoresheet)

print("\n 14-----------------------:")
print(scoresheet.interpolate(method='linear'))

运行:

 13-----------------------:
        Name  Economics  Statistics  Datamining  Exam_Date
0  Christoph         89          98        79.0 2017-07-07
1        NaN         97          93         NaN 2017-07-08
2     Michel         56          76         NaN        NaT
3       None         82          85        89.0        NaT

 14-----------------------:
        Name  Economics  Statistics  Datamining  Exam_Date
0  Christoph         89          98   79.000000 2017-07-07
1        NaN         97          93   82.333333 2017-07-08
2     Michel         56          76   85.666667        NaT
3       None         82          85   89.000000        NaT

你可能感兴趣的:(python学习)