Easily add new columns or remove data from your dataset in Pandas.
#AddRemoveData #DataCleaning #PythonData
#AddRemoveData #DataCleaning #PythonData
Category
📚
LearningTranscript
00:00data manipulation की discussion को आगे बढ़ाते हैं
00:02और data manipulation के अवाले से
00:04इस lecture के अंदर हम लोग तीन चीज़ें सीखने लगे हैं
00:07पहली चीज तो यह है किस तरीके से
00:09आप एक column add कर सकते हैं
00:11existing table के अंदर
00:12दूसरी चीज हम यह सीखेंगे किस तरीके से
00:15आप एक column को remove कर सकते हैं
00:17और तीसरा अगर एक column की values
00:19change करनी हो तो वो कैसे होगा तो चलिए सब से पहले
00:21तो हम add से शुरू करते हैं
00:23अच्छा एक चीज़ा आपने अपने जहन में रखनी है कि
00:25अगर यह देखिए मैं यहाँ पर variable call करता हूँ
00:27तो यह मुझे error देगा और उसकी reason
00:29मैंने शायद पहले भी बताई हो कि एक दफर जब आप
00:31जब आप जुपिटर नोटबुक को close करके दोबारा open करते हैं
00:33तो variable की values जो हैं वो lose हो जाती है
00:35तो इसलिए हम इसको दोबारा load करने लगए
00:37तो pd.read underscore csv करते हैं
00:41और इसके अंदर जो है
00:43मैं string के अंदर दूँगा
00:45clean data जो csv file last time हमने save की थी
00:47इसी को ही उठा लेते हैं
00:49ठीक है मैं इसको execute करता हूँ
00:51as you see हमारे पास जो है pd
00:53आ रहा है error क्योंकि मैंने
00:56इस cell को execute करना है
00:57ठीक है अब नीचे आते हैं और
00:59हम मैं run करता हूँ
01:01तो अब हमारे पास clean data आ गया हुआ
01:03मैं यहां पे इसको copy paste करके execute करते हैं
01:06तो यह देखे हमारे पास यह data table है
01:08जिसके अंदर five entries पड़ी हुई है
01:10सबसे पहले अगर आपने इसके अंदर कोई नया column add करना हो
01:14तो उसकी example ऐसे ही है
01:16जैसे कोई column को change करना हो
01:18ठीक है by default अगर वो column exist नहीं करता है
01:21तो new create हो जाता है
01:22अगर exist करता है
01:23तो existing के अंदर change आ जाती है
01:25तो यह काम तो हम पहले कहें ना
01:26मिसाल के तोर पे मैं अगर इस तरह कहता हूँ
01:28के एक नया column है
01:29let's say
01:29मैं नया column का नाम रख लेते हैं
01:33और नाम को रखता हूँ let's say battery
01:36battery ठीक है
01:38और battery को मैं कोई value assign करने लगा हूँ
01:42ठीक है
01:42और let's suppose के इस battery को जो मैं value assign करने लगा हूँ
01:47वो मैं create करूँगा एक series से
01:50अब series तो हमने already create की थी ना last time
01:54तो मैं दुबारा करी लगा हूँ
01:56B A T T R I S batteries is equal to P D dot S E R I S series
02:01अब इस series के अंदर मैं let's say number of batteries देने लगा हूँ
02:05और वो हैं जी let's say
02:073, 4, 3, 5 and 7
02:10ठीक है
02:11तो ये मैंने batteries डाल दी है
02:13ठीक है
02:13और batteries डाल दी है
02:14ठीक है
02:15और अब basically मैं ये जो batteries है ना
02:19ये add कर सकता हूँ
02:21इस column के अंदर
02:23अब एक नया column create होगा
02:25और उस column की जो values होंगी
02:27वो ये batteries को मैंने दी हैं जो
02:29वो assign हो जाएंगी
02:30तो मैं cell को execute करता हूँ
02:31और phone.csv दोबारा मैं आपको यहां पे दिखाता हूँ
02:34देखते हैं क्या है
02:35control V, control C
02:37अब जर आप गोर करें
02:38कि battery जो है यहां पे add हो गया हो है
02:40batteries का एक नया column
02:42ठीक है
02:43however आपने एक चीज़ नोट की
02:45कि total number of entries जो थी
02:47वो six थी
02:48लेकिन जो value मैंने दी
02:50वो value मैंने five दी
02:52तो इसलिए जो value missing थी
02:54वहां पे nan value आगे हुई है
02:57ठीक है
02:57अच्छा
02:58अब
02:59of course हमने यह सीखा हुआ है
03:01कि nan value को कैसे remove करते हैं
03:04यह तो हमें पता है ना
03:05तो
03:05इसी column को आपने पकड़ना है
03:07ठीक है
03:07इसी column को
03:08और आपने कहना है कि यार यही जो column है ना
03:11इसको fill na function डाल दो इसके ओपर
03:15fill na
03:16और fill na को कहो कि कौन सी value
03:19जो na पे आ रही है
03:21उस value को किस value से replace करना है
03:25let's say मैं कहता हूँ five replace करना है
03:28और उसके बाद अगर आपको मैंने बताया था कि
03:33देखें अगर मैं यह ऐसे execute कर देता हूँ ना
03:37तो value में change आएगी
03:39however original table के अंदर change reflect नहीं होगी
03:41इसलिए हमें in place is equal to true करना पड़ता है
03:44तो मैं in place is equal to true already यहाँ पर कर देता हूँ
03:48तो अब मैं जो change करूँगा
03:50वो basically आप देखेंगे कि यह nan जो है वो remove हो जाएगा
03:53तो चलिए इसको test करता है
03:54मैं इसको execute करता हूँ
03:55और again मैं phone underscore csv को यहाँ पर call करता हूँ
03:59run करते हैं
04:01अब run करते हैं
04:02आप देखिए कि उस nan की जगा पे
04:04अगर आप गोर करें यह nan है
04:06ठीक है जब हमने यह fill na run किया
04:09तो उसने na n के जगा 5 डाल दिया
04:11क्योंकि हमने इसको का था कि
04:12आपने 5 value को replace करना है
04:14very good
04:15तो एक method हमने सीख लिया
04:17एक नए column को create करने का
04:20ऐसा ही है ना
04:21अच्छा अब मैं आपको एक interesting चीज दिखाता हूँ
04:24आप थोड़ा से देख के हैरान भी होंगे और परिशान भी होंगे
04:26हमने अपने python के course के अंदर
04:30lists के बारे में सीखा था
04:32तो मैं इस तरह करता हूँ के
04:36एक feature add करता हूँ ringtone
04:38ठीक है ringtones
04:40एक ringtones है
04:41और उस ringtone के अंदर जो है
04:44let's say number of ringtones है
04:46हर phone के अंदर number of ringtones है
04:48लेकिन यह जो ringtones है
04:50यह एक python list है
04:51ठीक है एक python list है
04:54जिसके अंदर number of ringtones पड़ी हुई है
04:56तो मैं कोई random number of ringtones देने लगा हूँ
04:58let's say one
04:59five six eight seven
05:02let's say this much
05:06ठीक है
05:08अच्छे यह कोई random है
05:09मैंने को count नहीं किया कि कितनी
05:12ringtones है ठीक है
05:13अब जर आपने गहुर करना है
05:16यह one को मैं यहां से remove कर देता हूँ
05:18ठीक है
05:18अब number of ringtones हमारे पास है
05:22as a list
05:23अब जर आपने गहुर करना है
05:24मैं एक नया column create करने लगा हूँ
05:27ठीक है
05:27और उस column को हम कहते हैं
05:29कि जी ringtones
05:30ringtones
05:32और ringtones
05:34is equal to
05:35हमारी यह जो python list है
05:38ठीक है यह देखे
05:39अच्छा मैं इसको execute करता हूँ
05:42however
05:43यह हमें error दे रहा है
05:44और अगर आप थोड़ा सा error को गोर से पढ़ें
05:47बाइदबे यह error यहां से पढ़ना होता है आपने
05:49तो वो कह रहा है कि length of value
05:51do not match the length of index
05:53तो इसका मतलब यह है कि
05:55इसके अंदर entries है ना
05:58यह entries है
05:591, 2, 3, 4, 5 and 6 entries
06:021, 2, 3, 4, 5
06:05तो वो यह कह रहा है कि
06:07भाई
06:08जितनी entries आपके table में है
06:12exactly
06:12उतनी ही entries list के अंदर होनी चाहिए
06:16अगर आप
06:17एक नया column create करना चाहते हैं तो
06:19तो यह आपने फर्क देखना है
06:21कि series के अंदर आपको
06:23dimension mismatch problem
06:26नहीं आता
06:27however जब आप list के लिए डालते हैं
06:29जो python simple list यूज़ करते हैं
06:31तो उसमें dimension का exact होना बहुत जरूरी है
06:33अगर dimension mismatch होगी
06:35तो आपको error आएगा
06:36यह चीज़ आपने अपने जहन में रखनी है
06:38ठीक है
06:39तो अगर यहीं पर एक और value डालते हैं
06:43हमें पता है
06:43यह five values हैं already
06:44मैं एक और value डालता हूँ
06:45अब इसको execute करते हैं
06:48अब यह बिल्कुल perfectly execute हो गया हुए
06:50और आप देखेंगे कि नया
06:51ringtones का column आपके पास create हो गया हुए
06:54as you can see here
06:55ठीक है
06:56ठीक है तो चले आगे चलते हैं
07:00अब हमने दो काम किये
07:02हमने एक नया column create किया
07:04अब आप एक column को
07:14existing column से भी create कर सकते हैं
07:17very interesting
07:18तो चलिए मैं इस तरह करता हूँ
07:20कि एक नया column create करते हैं
07:22और उस column के खासियत यह होगी
07:23कि वो column battery और ringtone का product होगा
07:27battery और ringtone का product होगा
07:31वो कैसे करेंगे
07:32अब जब आपने गोर करना है
07:34ये देखिये ये मेरे पास है
07:35phone का data
07:36भीड़िवा है
07:37phone data है मेरे पास
07:38अब इस phone का
07:41जो मैंने
07:42column change करना है
07:44वो column उठाता हूँ
07:46ठीक है
07:47और
07:48let's say
07:49मैंने इसको जिस column के साथ
07:51change करना है
07:52मैं वो column उठाता हूँ
07:53तो मैं इसको इसको इसको ही पक्ड़के ना
07:55control c multiply control v ringtone control c and this operation I will assign one third
08:05column I am going to assign one third column and I am going to control c and this one is
08:17let's say product is equal to phone csv these are two columns which I am going to assign one third column
08:30I am going to execute it and now we will see the phone csv and what is the new column added
08:35as you can see that this product is displayed here and product is 1,3,3,2,4,8,5,5,25 and so on
08:46this was the same thing that if you operation and do existing columns you can create a column
08:53then you can create a single value as well as you can create a column that is how we can do it
08:58for example we will see this column and this one is the same thing and this one is the same thing
09:01I am going to say product csv and I am going to say new underscore column and new column is equal to
09:07three now I am going to execute it so I am going to say new column is the same thing that
09:12is the same thing that I am going to do it this is very cool huh
09:19this is very cool huh
09:21this is very cool huh
09:24this is very cool
09:27this is very cool
09:29is very cool huh
09:30this is very cool and back
09:32you can hear it
09:36this is very cool huh
09:38this is very cool
09:39I am going to call the say
09:40let's say
09:41safety
09:42battery safety
09:43safety, battery safety, and I will assign a boolean value to true.
09:48So I will execute this.
09:50You can see that we have again a boole column created,
09:54which is true.
09:56And if you run the D-type function,
09:59you will explain that it will be D, T, Y, P, E, S, D-type.
10:02Execute.
10:03You can see that you have a safety boolean function created,
10:08because we have created boolean function.
10:11This is how to create columns and different operations.
10:17If we remove the column, it will be very easy.
10:24We use the drop command.
10:27This is the table.
10:30We have drop call.
10:32Drop call.
10:35I will drop a new column.
10:38Ctrl-C.
10:39And here I will say, new column we have dropped.
10:44However, this information is not complete.
10:48If you remember, when I had to tell you,
10:50when I had to tell you that I had to tell you that I had two things.
10:56I said that a table is rows and columns.
11:00I have to tell you,
11:02that I have one column.
11:04اسی طرح میں نے یہ کہا تھا
11:06کہ جو horizontal direction میں آپ کو
11:08data نظر آ رہا ہے
11:09مثال کے طور پر
11:09ایک table
11:10ایک line لے رہا ہوں میں
11:12تو یہ جو ساری line ہے
11:14یہ ایک single row ہے
11:16ایسا ہی ہے نا
11:17اب میں نے یہ کہا تھا
11:18کہ یار یہ جو column ہوتا ہے نا
11:20اس کو axis is equal to one
11:22سے represent کرتے ہیں
11:23اور جو row ہے
11:24اس کو axis is equal to zero
11:25سے represent کرتے ہیں
11:26تو اب میں جب بھی drop کرنی ہوتی ہے نا
11:29values تو آپ نے بتانا ہوتا ہے
11:30کہ یار میں نے row drop کرنی ہے
11:32یا column drop کرنا ہے
11:33تو اس کے اس میں کیوں کہ
11:35ہم نے column drop کرنا ہے
11:36تو اس لیے میں drop کو آکے
11:38ایک extra information دوں گا
11:39اور کہوں گا
11:40axis is equal to one
11:43تو axis is equal to one کا مطلب ہے
11:45کہ column drop کرنا
11:46اور column کا نام ہے new column
11:48تو چلیئے اس کو execute کرتے ہیں
11:50اب ذرا آپ نے غور کرنا ہے
11:52کہ میں assignment نہیں کر رہا ہوں یہاں پہ
11:54تو دو طریقے ہیں
11:55یا تو میں اس کو ایک نئے
11:57اس کو ایسے reassign کروں
11:59ٹھیک ہے
12:00اسے کروں
12:01یا پھر
12:02یا پھر اگر میں یہ نہیں کرنا چاہتا
12:06تو یہیں پہ میں کر سکتا ہوں
12:08in
12:08place is equal to true
12:12however you like
12:13تو میں اس کو execute کرتا ہوں
12:15اور phone.csv کو
12:16آپ کو سامنے لے کے آتا ہوں
12:18دکھاتے ہیں جی
12:19تو آپ دیکھئے کہ
12:20آپ کے پاس جو new column ہے
12:21وہ remove ہو گیا ہوا ہے
12:23آپ کو یہاں پہ new column
12:24جو ہے وہ نظر نہیں آ رہا
12:26تو یہاں پہ اس lecture کو کرتے ہیں
12:28closed seat