Import Library¶
In [2]:
import numpy as np
import pandas as pd
Read CSV File¶
In [3]:
data = pd.read_csv('weather_data.csv')
data
Out[3]:
Check Rows and Columns¶
In [4]:
data.shape
Out[4]:
Data has 7 Rows and Columns
Check Data Type of Each Column¶
In [5]:
data.info()
Replacing Single Value with NaN¶
In [6]:
data
Out[6]:
Replace -99999 to NaN¶
In [7]:
data = data.replace(-99999,value=np.NaN)
data
Out[7]:
In [8]:
data.info()
Now we have 2 missing values in temperature and windspeed column respectively
Replacing List of Values with Single Value¶
In [9]:
data
Out[9]:
In [10]:
data = data.replace([32.0,7.0],value=99)
data
Out[10]:
Replacing Per Column¶
In [11]:
data
Out[11]:
Replace Temperature Column value 99, Windspeed Missing Value (NaN) and Event value 0 with value 100¶
In [12]:
data.replace({'temperature':99.0,'windspeed':np.nan,'event':'0'},100)
Out[12]:
Replacing by using Mapping¶
In [13]:
data
Out[13]:
In [14]:
data = data.replace({np.nan:69,'0':'Sunny'})
data
Out[14]:
In [15]:
data = pd.read_csv('weather2.csv')
data
Out[15]:
Remove mph
from windspeed & F
from Temperature¶
In [16]:
data = data.replace({'temperature':'[A-Za-z]','windspeed':'[A-Za-z]'},'',regex=True)
data
Out[16]:
Replacing Column Values with Another List of Values¶
In [17]:
d = {'score':['exceptional','average','good','poor','average','exceptional'],
'student':['Karan','Arpit','Varun','Robin','Akshay','Ankush']}
In [18]:
data = pd.DataFrame(d)
data
Out[18]:
Replace the value of Score Column with values 1,2,3,4 Respectively¶
In [19]:
data = data.replace(['poor','average','good','exceptional'],[1,2,3,4])
data
Out[19]: