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

  Рет қаралды 10,302

Ankit Bansal

Ankit Bansal

Күн бұрын

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

Пікірлер: 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.
@khushishrivastava331
@khushishrivastava331 Жыл бұрын
Please create a video for scenarios where Lambda function can be used.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Ok
@bodybuildingmotivation5438
@bodybuildingmotivation5438 Ай бұрын
make more scenerios base qut on python
@mihirsamant9352
@mihirsamant9352 Жыл бұрын
I dont know why Ankit is soo underrated on KZbin. 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 😊
@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
@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?
@saurabhkhopkar8388
@saurabhkhopkar8388 28 күн бұрын
Very helpful
@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
@pratibhamishra869
@pratibhamishra869 Жыл бұрын
Please post regular videos in This playlist. This is great actually!
@ankitbansal6
@ankitbansal6 Жыл бұрын
Sure
@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.
@ratneshraj4653
@ratneshraj4653 Жыл бұрын
Please continue the series just like SQL series. Thanks in advance
@ssteo4136
@ssteo4136 10 ай бұрын
thanks. very useful
@hameedkaryab
@hameedkaryab 10 ай бұрын
Thank you very much for the clear explanation.😊
@ankitbansal6
@ankitbansal6 10 ай бұрын
Glad it was helpful!
@Mayank-jw9yy
@Mayank-jw9yy 5 ай бұрын
Great video Ankit
@divsp777
@divsp777 Жыл бұрын
Thank you for this amazing video. kudos
@ankitbansal6
@ankitbansal6 Жыл бұрын
Glad you enjoyed it!
@sudiipkumarbasu4194
@sudiipkumarbasu4194 Жыл бұрын
Great experience
@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.
@sachin-b8c4m
@sachin-b8c4m Жыл бұрын
good
@rishav144
@rishav144 Жыл бұрын
great video sir ...need more pandas video
@ankitbansal6
@ankitbansal6 Жыл бұрын
Sure
@avi8016
@avi8016 Жыл бұрын
Great video as usual sir💯
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 😊
@ektakumari4496
@ektakumari4496 Жыл бұрын
👌grt content
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 😊
escape in roblox in real life
00:13
Kan Andrey
Рет қаралды 93 МЛН
Поветкин заставил себя уважать!
01:00
МИНУС БАЛЛ
Рет қаралды 6 МЛН
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 99 МЛН
How to filter a pandas DataFrame | 6 HELPFUL METHODS
17:27
Chart Explorers
Рет қаралды 30 М.
How do I select multiple rows and columns from a pandas DataFrame?
21:47
Data Science and ML: Using If-Else Condition on Pandas Dataframe
12:45
Loop / Iterate over pandas DataFrame (2020)
11:05
Chart Explorers
Рет қаралды 83 М.
escape in roblox in real life
00:13
Kan Andrey
Рет қаралды 93 МЛН