Python Pandas Tutorial (Part 6): Add/Remove Rows and Columns From DataFrames




[ad_1]

In this video, we will be learning how to add and remove our rows and columns.

This video is sponsored by Brilliant. Go to https://brilliant.org/cms to sign up for free. Be one of the first 200 people to sign up with this link and get 20% off your premium subscription.

In this Python Programming video, we will be learning how to add and remove rows and columns from dataframes using the append and drop methods. We will also see how we can create new columns by combining elements from existing ones. Let’s get started…

The code for this video can be found at:
http://bit.ly/Pandas-06

StackOverflow Survey Download Page – http://bit.ly/SO-Survey-Download

✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms

✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join

✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist
http://a.co/inIyro1

✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer

▶️ You Can Find Me On:
My Website – http://coreyms.com/
My Second Channel – https://www.youtube.com/c/coreymschafer
Facebook – https://www.facebook.com/CoreyMSchafer
Twitter – https://twitter.com/CoreyMSchafer
Instagram – https://www.instagram.com/coreymschafer/

#Python #Pandas

Source


[ad_2]

Comment List

  • Corey Schafer
    November 24, 2020

    Hey everyone. Hope you're all having a great weekend. I'm still working on finishing up the series. Let me know if there is anything specific you want me to cover. In the next video I'll be covering sorting, and some videos still to come include: working with dates, aggregating data, reading and writing to/from different sources, and a discussion on the recent Pandas version 1.0 release. Let me know if there is anything else you'd like to see! Thanks and have a good one!

  • Corey Schafer
    November 24, 2020

    Hey, Corey!
    You can simply delete columns by using "del" function.
    For example: del df['full_name']

  • Corey Schafer
    November 24, 2020

    Aside from the unparalleled level of instruction, the production of these videos is superb. Only one of the 5 commercial courses I have taken was in the same league.

  • Corey Schafer
    November 24, 2020

    At the point of 14:13 of this VDO, I got my query resolved ! Thanks & many likes from me 🙂

  • Corey Schafer
    November 24, 2020

    Awesome series!

  • Corey Schafer
    November 24, 2020

    Hello Sir , i get this error message while running this code : df[['first', 'second']]= df['full_name'].str.split(' ' , expand=True)
    error ":ValueError: Columns must be same length as key
    please guide

  • Corey Schafer
    November 24, 2020

    What will be the solution if I want to add new row in a dataframe whose value is from the existing dataframe…like for each row a new row will be created having all integer value added upto 1 and string will be appended with _ new…..can anyone help me out

  • Corey Schafer
    November 24, 2020

    @11:49 That's probably because appending is extending the memory required to store the database so it would need to create new memory anyway so it can't do it in place.

  • Corey Schafer
    November 24, 2020

    love..

  • Corey Schafer
    November 24, 2020

    Very well and clearly explained thanks 🙂

  • Corey Schafer
    November 24, 2020

    Can you pls tell me how can we use apply() to get the full_name column without using the String concatenation?

  • Corey Schafer
    November 24, 2020

    Hi i hope you are doing well @corey schafer
    I have a question as in this video you explain how to add and remove a row and also how to drop a column and how to combine two columns and how to split a column into two or multi columns but you didn't explain if i want to add a single columns
    So i search on internet for that and found some ans like
    1. Df['age']=['value you want to assign']
    2. Insert
    Df.insert(5,"age",[list of value you want to assign ]
    3. Assign
    Df.assign(name with ' '=[list you want to assign]
    They have a problem you have to assign exit amount of value your data frame have if you miss a single value its gives a error
    Also assign doesnt work at orginal data frame when i try inplace =True its creat a new column with name inplace and all value were True
    So why assign is not working and how can i lift a value empty or create a column without any value like nan

  • Corey Schafer
    November 24, 2020

    I am addicted to your lectures please upload Numpy tutorials too

  • Corey Schafer
    November 24, 2020

    for old version of pandas this works
    df.drop(['first', 'last'],axis=1, inplace=True)

  • Corey Schafer
    November 24, 2020

    how can i use this for multiple .csv file in folder

  • Corey Schafer
    November 24, 2020

    How to arrange our columns

  • Corey Schafer
    November 24, 2020

    thank for videos Corey, but next time I demand Bruce Wayne aka Batman and Clark Kent aka Superman )

  • Corey Schafer
    November 24, 2020

    Great teaching sir

  • Corey Schafer
    November 24, 2020

    Hi , to perform drop should i use df.drop(Column =[Col1,col2] or its ok to use df.drop([Col1,Col2,Col3],axis=1).
    hope there is no difference b/w both . please confirm.

  • Corey Schafer
    November 24, 2020

    Hi Corey. How do I filter out records where a specific column has values NaN

  • Corey Schafer
    November 24, 2020

    Thanks for this excellent video series on Pandas. Your style is much cleaner and easier to follow than by trying to read through the official docs and various Stackoverflow posts.
    I'd really like to see a video on the different df.merge variations, particularly using MultiIndex and handling duplicates.

  • Corey Schafer
    November 24, 2020

    I want to add a row which has index named as alphabetical as opposed to numerical indexed dataframes.

  • Corey Schafer
    November 24, 2020

    Wow, man! With a little bit of help from Google and your videos, I was able to automate an Excel File … Thank you and keep it going! You rock!

  • Corey Schafer
    November 24, 2020

    I thanked you in the previous video, this comment is just to support channel.

  • Corey Schafer
    November 24, 2020

    if you permanently want to delete columns use: .drop(['your_column_name'], axis=1, inplace=True)

  • Corey Schafer
    November 24, 2020

    hey man i have been watching your videos for a while …..can i get personal email i need help large data

  • Corey Schafer
    November 24, 2020

    Thaaaanks a lot :DDD

  • Corey Schafer
    November 24, 2020

    Thank you Brilliant for sponsoring this course. Many people are getting help as more and more data analytics jobs are coming, this video is must.

  • Corey Schafer
    November 24, 2020

    Hi ! df.append does not persist. When doing df after that , the new row is not added and neither is recognized by df.loc [ ] . Pls help??

  • Corey Schafer
    November 24, 2020

    would be great to have a machine learning series from you

  • Corey Schafer
    November 24, 2020

    Why does df[df[filt]].index return Int64Index([6], dtype='int64') and not either a series or dataframe of the index as an object?

  • Corey Schafer
    November 24, 2020

    After deleting the rows from a DataFrame using df = df.drop(index = df[df['last']=='Doe'].index), our indexes become 0,3,4. How can we make then 0,1,2?

  • Corey Schafer
    November 24, 2020
  • Corey Schafer
    November 24, 2020

    Hey there first of all i would like to thank you for your guidance i just had one issue while we were trying to add two different DataFrames and you said that if we wish to delete the last row
    with index number 4 i tried doing that and i am getting an error can you please help me out
    can i rather send you the snapshot of the juypter notebook to your-email address which is :
    coreymsschafer@gmail.com

  • Corey Schafer
    November 24, 2020

    Amazing

  • Corey Schafer
    November 24, 2020

    How to apply different aggregation function on different columns on same group object.

  • Corey Schafer
    November 24, 2020

    Getting Error while using drop in the snippet code.

    Hi Corey,

    i get the below error when i run the drop command. pls help

    ""—————————————————————————

    TypeError Traceback (most recent call last)

    <ipython-input-38-d190c4ede970> in <module>()

    1 # deleting column

    2

    —-> 3 df.drop(columns=['first', 'last'])

    TypeError: drop() got an unexpected keyword argument 'columns'""

  • Corey Schafer
    November 24, 2020

    Thank you Brilliant for sponsoring Corey.

  • Corey Schafer
    November 24, 2020

    Hi Corey, your tutorial are great, but it would be even better if you could put lesson index at the beginning instead of middle

Write a comment