Assignment 2
Assignment 2
2. filter the columns 'float_col', 'int_col' from the dataframe in one query. Hint-
use ix
method of dataframes. Also print without using ix method
import pandas as pd
import numpy as np
import matplotlib.pyplot
import math
data=pd.read_csv('F:\data7.csv')
data1=data.loc[:,data['float_col','int_col']]
print(data1)
3. filter the records from float_col having value greater than 0.15 and in separate
query
filter float_col value equal to 0.1
data=pd.read_csv('F:\data7.csv')
flot=np.array(data['float_col'])
for i in range(len(flot)):
if flot[i]>0.15:
print('value <1.5 is',flot[i])
for i in range(len(flot)):
if flot[i]==0.1:
print('value=',flot[i])
4. filter the records from data frame which satisfies both the conditions float_col
greater than 0.1 and int_col greater than 2
data=pd.read_csv('F:\data7.csv')
data1=data.loc[:,['float_col,int_col']]
for i in data1.itertuples():
if i[1]>0.15 and i[2]>2:
print(data[i])
data=pd.read_csv('F:\data7.csv')
data.rename(columns={'float_col':'New_name',
'int_col':'New_name2'},inplace=True)
print(data)
9. Drop the rows where any value is missing from the data frame
data=pd.read_csv('F:\data7.csv')
data.rename(columns={'float_col':'New_name',
'int_col':'New_name2'},inplace=True)
data1=data.drop(['New_name','New_name2'],axis=1)
print(data1)
16.When we want to send the same invitations to many people, the body of the mail
does not change. Only the name (and maybe address) needs to be changed.
import pandas as pd
import numpy as np
import matplotlib.pyplot
import math
data=pd.read_csv('F:\daata.txt',dtype=str)
Mailbody=pd.read_csv('F:\Mailbody.txt')
data1=np.array(data)
for i in range(len(data1)):
print(data1[i])
print('________________')
print(Mailbody)