Тёмный

Pandas Conditional Columns: Set Pandas Conditional Column Based on Values of Another Column 

datagy
Подписаться 5 тыс.
Просмотров 36 тыс.
50% 1

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

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 84   
@19AKS58
@19AKS58 4 месяца назад
There are SO many, quite frankly TOO many instructional videos, and they are tedious, too long, and unclear, but YOURS is EXACTLY on point
@datagy
@datagy 4 месяца назад
Thank you so much! I really appreciate it.
@guidysoll
@guidysoll Год назад
I spend two days looking for a solution for a conditional problem. This video was exactly what I needed. Thank you very much!!!
@datagy
@datagy Год назад
Thanks so much for the feedback!!
@wearerunnersw.a.r5613
@wearerunnersw.a.r5613 2 года назад
great explanation, used the numpy method. works brilliantly
@datagy
@datagy 2 года назад
Thanks so much!
@Dataanalyticspro
@Dataanalyticspro Год назад
Excellent video! Just what I need to solve a problem. Thank you!
@datagy
@datagy Год назад
Thank you!! I appreciate the comment!
@leandrorberto
@leandrorberto Год назад
Excellent video! Thanks!!!
@kawsydaisy
@kawsydaisy 2 года назад
Thus video is very helpful and exactly what I needed! Thank you for the multiple examples with different scenarios!
@datagy
@datagy 2 года назад
Thank you so much!
@kennethstephani692
@kennethstephani692 Год назад
Great video!
@datagy
@datagy Год назад
Thanks Kenneth!
@Troiler
@Troiler 2 года назад
heey!! this video provides everything I need for a project I have in mind..
@brtb3
@brtb3 2 года назад
The numpy option was exactly what I needed and worked great. Thank you, also for the other videos. Keep up the good work…
@datagy
@datagy 2 года назад
Thanks so much for your feedback! 😊
@melodic_tech_house
@melodic_tech_house Год назад
For me too
@victormadoya1354
@victormadoya1354 8 месяцев назад
HI, what if you want to create a similar function with takes 2 values? such that the 2 values will be 2 columns rather than using one column. The def function to take 2 columns instead of one, then use apply function
@CX004
@CX004 2 года назад
Awesome! Could you show an example taking in 2 parameters instead? Say taking Age and Gender... How do we achieve that using the function-apply approach?
@thetudors9875
@thetudors9875 2 года назад
Excellent presentation… you really helped me understand map & apply methods
@datagy
@datagy 2 года назад
I'm so glad it was helpful!
@alihobballah
@alihobballah Год назад
This is an excellent Tutorial !!! . Beautifully explained, and you went over issues I have been struggling with. Thank you so much for taking the time to make this video
@datagy
@datagy Год назад
Thanks so much Ali!
@Zenoandturtle
@Zenoandturtle 10 месяцев назад
Great presntation. I am building a trading bot using algorythm that deals with conditional columns (candlestick lengths of previous columbs) This is the video I was looking for. Thanks for the vid. Very clear and informative. Exactly what I was looking for.
@georgiyveter6391
@georgiyveter6391 Год назад
Hi, for example I have a table, which I've got by left outer join: person - vehicle dad - car dad - motorcycle dad - bicycle mom - car mom - bicycle son - None/NA/NaN/NaT How to group by person and count with condition (car and motorcycle)? When I use for example: df = df.groupby(['person'])['vehicle'].apply(lambda x: x[x == 'car'].count()) But I can't use a list in condition lambda x: x[x in ['car']], pandas says: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
@diaconescutiberiu7535
@diaconescutiberiu7535 Год назад
What about if i have a column that contains several words (on each row) and i need to create a new column with 1s/0s IF ... my records contain a specific word AND (at same time) doesn't contain (another) specific word. I want to flag those records
@sepidehdavoudian5580
@sepidehdavoudian5580 Год назад
Hi Thank you. I constantly receive this error, could you please help? 'NAType' object has no attribute 'str'
@sepidehdavoudian5580
@sepidehdavoudian5580 Год назад
def SAPID (TotalData1): if (TotalData1['Type_SubCat']=='Billing'): return TotalData1['Sales Document'] elif (TotalData1['User Name']=='ANSAZIY'): return 'OPENNING BALANCE' elif (TotalData1['Assignment'].str[0]=='4'): return TotalData1['Assignment'].str[10] elif (TotalData1['Assignment'].str[0]=='L'): return TotalData1['Assignment'].str[8] else: return TotalData1['Assignment']
@datagy
@datagy Год назад
It’s likely that you have missing data in your column - you can fill those first before applying the conditional column.
@kathryngomes7869
@kathryngomes7869 Год назад
This is really awesome. Thankyou for this tutorial.
@datagy
@datagy Год назад
Thanks so much!
@munivoltarc
@munivoltarc 9 месяцев назад
Hi, you are doing awesomely work, explaining subject so easily to all, wondaful work, keep it up, could you explain OHLCV data, apply, map functions, user defined functions to to find the trend on the High, Low columns, to get buy signals and sell signals by not using any price lagging indicators.
@sonal008
@sonal008 Год назад
I have 4 lac records. And I have to assign url based unique ID.. how I can do that?
@zarirramiz8978
@zarirramiz8978 2 года назад
Thanks for clear explanation🎉
@datagy
@datagy 2 года назад
Thanks Zarir!
@introduccionalageometalurg2797
@introduccionalageometalurg2797 2 года назад
Thanks for the useful lesson.
@datagy
@datagy 2 года назад
I'm glad it was helpful!
@hashemrashidi1277
@hashemrashidi1277 5 месяцев назад
Guys he is the best and simplest , best one seriously , just trust and watch till the end .
@ajibademotunrayo8453
@ajibademotunrayo8453 2 года назад
Hi how do you replace zero values in a column based on multiple conditions
@maxons.e4643
@maxons.e4643 2 года назад
I will be very very grateful if you could reply this. i am on a hot seat.
@DavidWhiteJazz
@DavidWhiteJazz Год назад
This was a clear and concise explanation that helped me a lot. Thank you for all that you do!
@datagy
@datagy Год назад
Thank you SO much David! That was very generous of you! I’m so glad you liked the video!
@Zenoandturtle
@Zenoandturtle 10 месяцев назад
One of the best I had seen.
@AndrewCB07
@AndrewCB07 2 года назад
I've been looking for a video to help with my code for days. Your vid was by far the best and only one that added value. Well done!
@datagy
@datagy 2 года назад
Thanks so much, Andrew!
@GauravDhage
@GauravDhage 2 года назад
Thanks man!
@datagy
@datagy 2 года назад
Thanks for your comment!
@zainhana2968
@zainhana2968 2 года назад
Can u give me an example if using nested conditional? Because when I have tried my nested conditional with function and loop, the value in new coloumn is nan
@Sandeepkumar-dm2bp
@Sandeepkumar-dm2bp 2 года назад
Excellent tutorial nice explanations, concise, covered many related concepts, various ways to do,
@datagy
@datagy 2 года назад
Thank you so much!
@Puma_178
@Puma_178 2 года назад
your video is so good, thank u so much I was looking for this everywhere :)
@datagy
@datagy 2 года назад
Thank you! That means a lot!
@maxons.e4643
@maxons.e4643 2 года назад
This is great. But I need to do this for multiple columns. How do add values from another column to the new column without it affecting the existing values (except where there is null?
@firdi3216
@firdi3216 Год назад
wow bro. that is very helpful. from indonesia, thank you..
@datagy
@datagy Год назад
Thanks Firdi!!
@thecommonwheel
@thecommonwheel 2 года назад
Excellent. Thanks for sharing your knowledge.
@datagy
@datagy 2 года назад
Thanks Zac!
@sonkamblepraveenkumar8230
@sonkamblepraveenkumar8230 2 года назад
Thank you bro that what i was looking for my problem to be solved. Great!!!!
@Planetknowledge555
@Planetknowledge555 5 месяцев назад
Excellent
@amirarsalanghazali1363
@amirarsalanghazali1363 2 года назад
thanks a lot, you saved me a lot of time and effort
@datagy
@datagy 2 года назад
I’m so glad!!
@Drezzomir
@Drezzomir 2 года назад
Works like a charm! Many thanks dude :)
@datagy
@datagy 2 года назад
Thanks Andrés!
@jacksparrowcapitan3232
@jacksparrowcapitan3232 2 года назад
That's helpful beginner stuff, Thanks
@datagy
@datagy 2 года назад
I’m glad it was helpful!
@andyb1322
@andyb1322 Год назад
Oh man -- I've been trying to figure out more efficient ways of defining bins for a df. While I'm fairly new to Python, I've coded (in SAS) for 15 years, but that experience is only helpful in knowing how I would solve a coding problem -- in SAS. The numpy approach you mentioned is very simple and intuitive -- your tips are going to save me so much time! Thanks for making this video!!!
@datagy
@datagy Год назад
Thank you so much for this comment Andy! Made my day!
@felixr1004
@felixr1004 2 года назад
Great explanation
@datagy
@datagy 2 года назад
Thank you!
@Mmmkay..
@Mmmkay.. 2 года назад
great video !
@datagy
@datagy 2 года назад
Thank you!!
@Gaming_Hub47
@Gaming_Hub47 2 года назад
h=1 temp=h height=[] for i in range(60): if a[i]>b[i]: h=2 temp=h height.append(h) elif a[i]
@datagy
@datagy 2 года назад
Hey Abhishek, sorry, I’m not sure what you’re hoping to accomplish. Could you elaborate?
@Gaming_Hub47
@Gaming_Hub47 2 года назад
@@datagy we have two lists here, list a[] and b[] which contains some values, and the length of each lists is 60 thats why the for loop range is 60, then in the first 'if' condition if the 'i' value of the list a[] is greater then 'i' value of list b[] then the value of h will be 2 and we will append the value of h in the height[] list and similar condition is for second elif condition too but if both the condition fails then the value of h will be whatever the previous value of h, and i used temp variable to accomplish that....so how i will change all these scenarios according to the data frame......where list a and b are now two columns of the dataframe and instead of appending the values of h into a list i want to create a new column in the dataframe which will store it.....i hope that now it clears all the condition ......please help if possible.. it is like how can we compare 2 columns of a dataframe and if possible then how can we assign h the previous value when both the condition fails
@datagy
@datagy 2 года назад
@@Gaming_Hub47 Thanks for the explanation! I'm struggling to picture the flow of the data. Can you include the list a and b for me to better understand? Happy to try and help!
@Gaming_Hub47
@Gaming_Hub47 2 года назад
@@datagy really sry i missed the point that there is 3 list ....now i corrected the code, there is a list c also ....this problem is so confusing.....i really appreciate that you try to solve my issue........ list a is=[88.85, 88.645, 88.985, 88.775, 88.745, 89.165, 89.495, 88.905, 88.9, 89.015, 89.295, 89.325, 89.375, 89.265, 89.415, 89.465, 89.54, 89.54, 89.24, 89.16, 89.155, 89.155, 89.095, 89.22, 89.2, 89.245, 89.365, 88.935, 89.33, 89.325, 89.185, 88.885, 88.645, 88.65, 88.215, 88.18, 88.575, 88.595, 88.535, 88.585, 88.52, 88.765, 88.97, 88.965, 88.91, 88.69, 88.99, 89.055, 88.75, 88.63, 88.625, 88.39, 88.415, 88.33, 88.76, 88.585, 88.56, 88.85, 88.88, 89.03, 89.575, 89.56, 89.7, 90.395, 90.335, 89.875, 88.845, 88.94, 88.77, 88.61, 88.845, 88.47, 88.615, 88.7, 88.725, 88.9, 88.455, 88.48, 88.655, 88.49, 88.37, 88.535, 88.45, 88.5, 88.885, 88.72, 88.815, 88.905, 88.775, 88.88, 89.14, 89.425, 89.315, 89.005, 89.4, 89.405, 89.38, 89.17, 89.465, 89.19, 89.11, 89.245, 89.28, 89.26, 89.02, 88.865, 88.98, 88.93, 88.87, 88.67, 88.75, 88.895, 88.9, 88.915, 89.15, 89.285, 89.285, 89.05, 88.905, 89.06] list b is= [nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 89.618, 89.668, 89.672, 89.619, 89.523, 89.413, 89.307, 89.226, 89.192, 89.199, 89.241, 89.291, 89.348, 89.384, 89.376, 89.293, 89.16, 88.997, 88.773, 88.609, 88.502, 88.471, 88.498, 88.533, 88.604, 88.709, 88.821, 88.925, 89.006, 89.057, 89.096, 89.122, 89.092, 89.024, 88.935, 88.798, 88.675, 88.608, 88.589, 88.597, 88.65, 88.738, 88.854, 89.111, 89.403, 89.663, 89.975, 90.277, 90.515, 90.62, 90.475, 90.184, 89.776, 89.409, 89.12, 88.852, 88.675, 88.581, 88.594, 88.653, 88.673, 88.694, 88.697, 88.682, 88.663, 88.63, 88.6, 88.659, 88.748, 88.851, 88.956, 89.04, 89.086, 89.164, 89.254, 89.352, 89.427, 89.503, 89.555, 89.59, 89.591, 89.572, 89.555, 89.507, 89.438, 89.371, 89.331, 89.302, 89.242, 89.178, 89.123, 89.07, 89.013, 88.931, 88.87, 88.837, 88.839, 88.892, 88.999, 89.124, 89.238, 89.293, 89.304] l [nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 89.442, 89.467, 89.441, 89.378, 89.281, 89.179, 89.09, 89.025, 89.008, 89.025, 89.024, 89.004, 89.023, 89.053, 89.05, 88.984, 88.867, 88.667, 88.385, 88.141, 88.009, 87.993, 88.06, 88.162, 88.275, 88.414, 88.563, 88.703, 88.792, 88.833, 88.871, 88.878, 88.837, 88.765, 88.654, 88.532, 88.411, 88.312, 88.262, 88.264, 88.312, 88.427, 88.563, 88.727, 88.939, 89.156, 89.393, 89.688, 89.914, 89.914, 89.713, 89.408, 89.009, 88.664, 88.378, 88.14, 88.032, 88.02, 88.098, 88.203, 88.281, 88.329, 88.371, 88.378, 88.348, 88.312, 88.29, 88.307, 88.375, 88.46, 88.557, 88.655, 88.732, 88.784, 88.873, 88.983, 89.059, 89.101, 89.162, 89.232, 89.269, 89.266, 89.242, 89.187, 89.126, 89.044, 89.003, 88.968, 88.93, 88.891, 88.843, 88.81, 88.758, 88.693, 88.634, 88.598, 88.611, 88.66, 88.759, 88.898, 89.007, 89.069, 89.067]
@Gaming_Hub47
@Gaming_Hub47 2 года назад
so these are the 3 lists .....please now try the code with all the values in ....maybe now it is somewhat easy
@eldrigeampong8573
@eldrigeampong8573 2 года назад
Superb tutorial. Keep it up
@datagy
@datagy 2 года назад
Thanks so much!
@eldrigeampong8573
@eldrigeampong8573 2 года назад
@@datagy My pleasure
@juliobarber4206
@juliobarber4206 2 года назад
😃 P R O M O S M!
Далее
Лиса🦊 УЖЕ НА ВСЕХ ПЛОЩАДКАХ!
00:24
🦊🔥
00:16
Просмотров 487 тыс.
I Built a SECRET Lamborghini Dealership!
33:02
Просмотров 6 млн
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
How do I use the MultiIndex in pandas?
25:01
Просмотров 174 тыс.
Python Map Function
13:40
Просмотров 4,9 тыс.