Тёмный

How to compare columns in pandas 

Chart Explorers
Подписаться 11 тыс.
Просмотров 18 тыс.
50% 1

In this video we go over how to compare columns in a pandas DataFrame. We also go over some issues to look out for when compare column values.
We create a new column with Boolean values to indicate everywhere that our comparison was satisfied.
We also discuss how to use arithmetic with Boolean values.
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
$15 off Annual Dataquest subscription
app.dataquest.io/referral-signup/qybqz3r8/
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Did you find this video helpful? Consider subscribing for weekly tips, tricks, and tutorials.
/ @chartexplorers
0:00 Intro
0:08 Setup
0:27 Compare Columns
0:53 Operators
1:04 Gottcha
127 Arithmetic & Boolean

Наука

Опубликовано:

 

13 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 24   
@mrmuranga
@mrmuranga 3 года назад
awesome.....keep making these informative short videos
@ChartExplorers
@ChartExplorers 3 года назад
Will do! Thanks for your encouragement.
@studyhub3950
@studyhub3950 3 года назад
very good helping and informative and short. keep it up.
@ChartExplorers
@ChartExplorers 3 года назад
Thank you!
@shobhitasohal2853
@shobhitasohal2853 2 года назад
hey. Can we use if statement to compare 2 columns in a new column & return certain value other than just true or false?
@jayineedesai7322
@jayineedesai7322 2 года назад
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?
@tanliz765
@tanliz765 3 года назад
Thank you!
@ChartExplorers
@ChartExplorers 3 года назад
You're Welcome! :)
@vinayakchikkorde8151
@vinayakchikkorde8151 2 года назад
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?
@sanahnahk7312
@sanahnahk7312 3 года назад
thanks !
@ChartExplorers
@ChartExplorers 3 года назад
You're Welcome!
@salman_shaikh
@salman_shaikh 2 года назад
unable to compare same thing with float values. getting incorrect result
@bitwamet
@bitwamet 2 года назад
How to add multiple condition
@gussta1
@gussta1 3 года назад
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
@ChartExplorers
@ChartExplorers 3 года назад
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)
@khushbugupta6970
@khushbugupta6970 2 года назад
how to compare one column with the other 16 columns? These 16 columns are not next to each other.
@miss_tech
@miss_tech 2 года назад
ValueError: Can only compare identically-labeled Series objects
@hellofrombd1960
@hellofrombd1960 3 года назад
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
@ChartExplorers
@ChartExplorers 3 года назад
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.
@noob_coder001
@noob_coder001 2 года назад
Comapare two colums get the records from one column..EXAMPLE A column values == Bcolummn values same print(Common values )😭😭
@BhanuLekha
@BhanuLekha 3 года назад
How to code for how many trues r there
@ChartExplorers
@ChartExplorers 3 года назад
Do you want to count the number of True values in a column? df['col_name'].sum()
@BhanuLekha
@BhanuLekha 3 года назад
@@ChartExplorers s I need no.of true values in the column after comparing .thank u
@ChartExplorers
@ChartExplorers 3 года назад
@@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()
Далее
Cumulative Sum in Pandas
2:40
Просмотров 6 тыс.
How Many Balloons Does It Take To Fly?
00:18
Просмотров 69 млн
How do I use the MultiIndex in pandas?
25:01
Просмотров 172 тыс.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
How To Compare CSV Files For Differences in Python
11:19
Loop / Iterate over pandas DataFrame (2020)
11:05
Просмотров 80 тыс.
How slow is iterating over a pandas DataFrame?
6:34
Compare excel files using Python with Pandas
11:23
Просмотров 49 тыс.