Importing packages¶
In [1]:
import numpy as np
import pandas as pd
pd.options.display.width = 1000
Creating sample dataframe¶
In [2]:
df = pd.DataFrame(
{'shop': [101, 101, 101, 102, 102, 102, 103, 103, 103, 103],
'price': [75, 150, 300, 300, 600, 600, 1000, 1000, np.nan, np.nan]})
Group By¶
In [3]:
grouped = df.groupby('shop')['price']
print(type(grouped))
Checking for Null values in each group¶
In [4]:
df['has_null'] = grouped.transform(lambda x: pd.isnull(x).any()).astype(bool)
In [5]:
df
Out[5]: