Hi @chart Explorers , i have one doubt.. when i used the same method shown here ..it is giving TypeError: unhashable type: 'Series' can you please tell me how to resolve this?
Instead of it saying True / False, is there a way to make say any type of "string value", like high / low or full / empty...anything other than True / False
This is a little cluncky df['boo'] = (df['col1'] < df['col2']).apply(lambda x: 'Less than' if True else 'Greater than eqaul to') or you could use something slightly more performant condlist = [df['col1'] < df['col2'],df['col1'] >= df['col2']] choicelist = ['Less than', 'Greater than'] df['boo'] = np.select(condlist, choicelist) Let me know if you want an explanation (I won't be able to give it for the next 10 hours or so)
I have the source file and target file. so in that, I have to compare 140 columns and show the result if it matches or not. for example, there is a column as Country1 in source and in target as Country2. to compare that i will use if(source['country1]==target['country2])return True else return false. to compare 140+ columns it will take time to compare 140 columns. so how can I solve this?
Good catch. This was an editing mistake, I had provided more examples in my original explanation, but edited them out. If you notice at 1:46 seconds we get the expected answer (2) and then I cut out my other examples in editing. I'll see what I can do to fix this. Thanks.
@@BhanuLekha A neat feature of boolean values (True and False) is that they are considered as 1's and 0's. So you can use mathematical operations on them just like a floats or ints. If all you need is the sum you can : (df['Col_1'] > df['Col_2']).sum() Or you could create a new column (like in the video) and then sum the column. df['new_col'] = df['Col_1'] > df['Col_2'] df['new_col'].sum() This will return all the number of true values. If you wanted the number of False values len(df) - (df['Col_1'] > df['Col_2']).sum()
awesome.....keep making these informative short videos
Will do! Thanks for your encouragement.
very good
helping and informative and short. keep it up.
Thank you!
Hi @chart Explorers , i have one doubt.. when i used the same method shown here ..it is giving TypeError: unhashable type: 'Series' can you please tell me how to resolve this?
Instead of it saying True / False, is there a way to make say any type of "string value", like high / low or full / empty...anything other than True / False
This is a little cluncky
df['boo'] = (df['col1'] < df['col2']).apply(lambda x: 'Less than' if True else 'Greater than eqaul to')
or you could use something slightly more performant
condlist = [df['col1'] < df['col2'],df['col1'] >= df['col2']]
choicelist = ['Less than', 'Greater than']
df['boo'] = np.select(condlist, choicelist)
Let me know if you want an explanation (I won't be able to give it for the next 10 hours or so)
hey. Can we use if statement to compare 2 columns in a new column & return certain value other than just true or false?
unable to compare same thing with float values. getting incorrect result
I have the source file and target file. so in that, I have to compare 140 columns and show the result if it matches or not. for example, there is a column as Country1 in source and in target as Country2. to compare that i will use if(source['country1]==target['country2])return True else return false. to compare 140+ columns it will take time to compare 140 columns. so how can I solve this?
how to compare one column with the other 16 columns? These 16 columns are not next to each other.
Thank you!
You're Welcome! :)
How
0
5
5
5
5
5
Comes???? Don't understand. If False means 0 then df['boo']+1 would be 0+1=1
Then 1+1=2
2
2
2
Good catch. This was an editing mistake, I had provided more examples in my original explanation, but edited them out. If you notice at 1:46 seconds we get the expected answer (2) and then I cut out my other examples in editing. I'll see what I can do to fix this. Thanks.
Comapare two colums get the records from one column..EXAMPLE A column values == Bcolummn values same print(Common values )😭😭
ValueError: Can only compare identically-labeled Series objects
How to add multiple condition
thanks !
You're Welcome!
How to code for how many trues r there
Do you want to count the number of True values in a column? df['col_name'].sum()
@@ChartExplorers s I need no.of true values in the column after comparing .thank u
@@BhanuLekha A neat feature of boolean values (True and False) is that they are considered as 1's and 0's. So you can use mathematical operations on them just like a floats or ints.
If all you need is the sum you can :
(df['Col_1'] > df['Col_2']).sum()
Or you could create a new column (like in the video) and then sum the column.
df['new_col'] = df['Col_1'] > df['Col_2']
df['new_col'].sum()
This will return all the number of true values. If you wanted the number of False values
len(df) - (df['Col_1'] > df['Col_2']).sum()