I
have an excel sheet with below records
Post Reference: Vikram Aristocratic Elfin Share
Here we are trying to implement various filter criteria
·
Implementing value
search
·
Implementing like condition
·
Implementing not
like condition
And while doing these we will try to ignore the NULL condition with the
help of “na=Falase” parameter. Lets code it
import pandas as pd
import numpy as np
df1 = pd.read_csv("NullFilterExample.csv")
print('Original DF rows \n',df1 , '\n')
#implementing value search
df2=df1[df1.customer_name == 'Rishika']
print('Rows where customer Name like Rishika \n',df2)
#implementing like condition
df3 = df1[df1.customer_name.str.contains('ika', na=False)]
print('Rows where customer Name contain ika \n',df3)
#implementing not like condition
df4 = df1[~df1.customer_name.str.contains('ika', na=False)]
print('Rows where customer Name not contain ika \n',df4)
import numpy as np
df1 = pd.read_csv("NullFilterExample.csv")
print('Original DF rows \n',df1 , '\n')
#implementing value search
df2=df1[df1.customer_name == 'Rishika']
print('Rows where customer Name like Rishika \n',df2)
#implementing like condition
df3 = df1[df1.customer_name.str.contains('ika', na=False)]
print('Rows where customer Name contain ika \n',df3)
#implementing not like condition
df4 = df1[~df1.customer_name.str.contains('ika', na=False)]
print('Rows where customer Name not contain ika \n',df4)
Output:
Original DF rows
account_no branch
city_code customer_name amount
0 2112 3212.0
321.0 Sidhika 19000
1 2119 NaN
215.0 Prayansh 12000
2 2115 4321.0
212.0 Rishika 15000
3 2435 2312.0
NaN Sagarika 13000
4 2356 7548.0
256.0 NaN 15000
Rows where customer Name like Rishika
account_no branch
city_code customer_name amount
2 2115 4321.0
212.0 Rishika 15000
Rows where customer Name contain ika
account_no branch
city_code customer_name amount
0 2112 3212.0
321.0 Sidhika 19000
2 2115 4321.0
212.0 Rishika 15000
3 2435 2312.0
NaN Sagarika 13000
Rows where customer Name not contain ika
account_no branch
city_code customer_name amount
1 2119 NaN
215.0 Prayansh 12000
4 2356 7548.0
256.0 NaN
15000
Data Science with…Python :)
No comments:
Post a Comment