Sei sulla pagina 1di 2

1.

Create a pandas dataframe having following structure

float_col int_col str_col


0 0.1 1 a
1 0.2 2 b
2 0.2 6 None
3 10.1 8 c
4 NaN -1 a

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])

7. Create a new data frame in which column int_col is renamed to new_name.


8. Modify the existing data frame and rename the column int_col to new_name

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)

Potrebbero piacerti anche