Тёмный

How to Create Conditional Columns in Pandas | IF ELSE Condition in Pandas Data Frame 

Ankit Bansal
Подписаться 122 тыс.
Просмотров 10 тыс.
50% 1

In this video we will learn how to create new columns in pandas based on the value of other columns.
data:
order_id,product_name,category,city,sales,profit
CA-2020-152156,p1,Furniture,Bangalore,10000,500
CA-2020-138688,p2,Furniture,Bangalore,20000,400
US-2019-108966,p3,Technology,Chennai,25000,200
CA-2021-114412,p4,Office Supplies,Chennai,30000,250
CA-2020-161389,p5,Technology,Mysore,35000,800
US-2019-118983,p6,Office Supplies,Mysore,40000,700
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
#python #pandas #dataanalytics

Наука

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

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@sashikanthpalleti5757
@sashikanthpalleti5757 Год назад
The operation is happening row by row. I was asked in an interview with ServiceNow how to add a new column in pandas dataframe with existing column string length without using row by row operations. Ex: Sno name 1 abch 2 sujit 3 pqr Output: Sno name length 1 abch 4 2 sujit 5 3 pqr 3
@ankitbansal6
@ankitbansal6 Год назад
That you can simply create using df['len']= df.name.str.len()
@sashikanthpalleti5757
@sashikanthpalleti5757 Год назад
@@ankitbansal6 I said i will use the apply() method and they were not convinced. What is the difference in apply() method and directly using Len() ?
@ankitbansal6
@ankitbansal6 Год назад
@@sashikanthpalleti5757 apply function is a loop itself. Direct assignment is a dataframe operation and faster.
@Mayank-jw9yy
@Mayank-jw9yy 5 месяцев назад
Great video Ankit
@parveen8122
@parveen8122 Год назад
Solution using apply function ========================= using apply function , I think it wii be much more efficient and increases readibility. in your case i think the same df will run twice , 1st for KN and then for TN def match(city): if city=="Bangalore" or city=='Mysore': return 'Karnataka' else: return 'TN' df["State"] = df["city"].apply(match)
@ankitbansal6
@ankitbansal6 Год назад
Apply runs a loop
@sudiipkumarbasu4194
@sudiipkumarbasu4194 Год назад
Great experience
@bodybuildingmotivation5438
@bodybuildingmotivation5438 Месяц назад
make more scenerios base qut on python
@mihirsamant9352
@mihirsamant9352 Год назад
I dont know why Ankit is soo underrated on RU-vid. He got skills to make difficult topic super easy. Thanks for doing this but you are tooo good with skills and knowledge #Respect !
@ankitbansal6
@ankitbansal6 Год назад
Thank you 😊
@khushishrivastava331
@khushishrivastava331 Год назад
Please create a video for scenarios where Lambda function can be used.
@ankitbansal6
@ankitbansal6 Год назад
Ok
@ektakumari4496
@ektakumari4496 Год назад
👌grt content
@ankitbansal6
@ankitbansal6 Год назад
Thank you 😊
@arunshaw1285
@arunshaw1285 Год назад
Solution using numpy's # np.select(conditions, values) import numpy as np conditions = [(df['profit']250) & (df['profit']500)] values=['low','medium','high'] df['profit_category'] = np.select(conditions,values) df
@saurabhkhopkar8388
@saurabhkhopkar8388 Месяц назад
Very helpful
@LONGTRINH-ut4nt
@LONGTRINH-ut4nt Год назад
how i can compare 2 columns using if else in order to classify? Ex: [Column A > Column B: 'Good Customer' else 'Bad Customer']
@SheikhSirajumMonir
@SheikhSirajumMonir 9 месяцев назад
were you able to find a solution for it?
@sonal008
@sonal008 Год назад
How to do this for for bigger dataset. Like I have 354 unique product ID and I have to assign Url to each in new column.
@pratibhamishra869
@pratibhamishra869 Год назад
Please post regular videos in This playlist. This is great actually!
@ankitbansal6
@ankitbansal6 Год назад
Sure
@ratneshraj4653
@ratneshraj4653 Год назад
Please continue the series just like SQL series. Thanks in advance
@ssteo4136
@ssteo4136 10 месяцев назад
thanks. very useful
@sachin-b8c4m
@sachin-b8c4m Год назад
good
@hameedkaryab
@hameedkaryab 10 месяцев назад
Thank you very much for the clear explanation.😊
@ankitbansal6
@ankitbansal6 10 месяцев назад
Glad it was helpful!
@divsp777
@divsp777 Год назад
Thank you for this amazing video. kudos
@ankitbansal6
@ankitbansal6 Год назад
Glad you enjoyed it!
@rishav144
@rishav144 Год назад
great video sir ...need more pandas video
@ankitbansal6
@ankitbansal6 Год назад
Sure
@shravank1147
@shravank1147 Год назад
amazing ... its helpful..please upload more vids on pandas
@ankitbansal6
@ankitbansal6 Год назад
Sure
@salmankhan-vq7pc
@salmankhan-vq7pc Год назад
@@ankitbansal6 Hi bro, this is the playlist im looking for. Very helpful. Kindly create more content on pandas and numpy. Cheers.
@avi8016
@avi8016 Год назад
Great video as usual sir💯
@ankitbansal6
@ankitbansal6 Год назад
Thank you 😊
Далее
How do I use the MultiIndex in pandas?
25:01
Просмотров 174 тыс.
How to filter a pandas DataFrame | 6 HELPFUL METHODS
17:27
Make Your Pandas Code Lightning Fast
10:38
Просмотров 184 тыс.
The Sad Reality of Being a Data Scientist
8:55
Просмотров 67 тыс.