I have a dataframe like this
name data result
0 x 100
1 x 100
2 x 100
3 x 100
4 x 100
5 y 100
6 y 90
7 y 90
8 y 100
9 y 85
I want to check whether each group in the name
column have the same value in the data
column.
So for each x
group, if the corresponding data
value are all equal, write full
in the result
column. If the values for a group not are all equal, write nearly
in the result
column.
I have tried grouping the dataframe:
dfx = df.groupby('name')
dfx = dfa.get_group('x')
but it doesn't really help in checking if each value is the same, write in the result
column.
I have tried creating a function that will check for unique values
def check_identicals(row):
if(df.sent.nunique() == 1):
print('Full')
The idea here is to then apply that function to each row and write the output in the result
column.
Ideal output:
name data result
0 x 100 full
1 x 100 full
2 x 100 full
3 x 100 full
4 x 100 full
5 y 100 nearly
6 y 90 nearly
7 y 90 nearly
8 y 100 nearly
9 y 85 nearly