Python Pandas Tutorial (Part 10): Working with Dates and Time Series Data

In this video, we will be learning how to work with DateTime and Time Series data in Pandas.
This video is sponsored by Brilliant. Go to 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 several different concepts about working with DateTimes and Time Series data in Pandas. We will learn how to convert values to datetimes, how to filter by dates, how to resample our dates to do some more in-depth analysis, and more. Let's get started...
The code for this video can be found at:
bit.ly/Pandas-10
StackOverflow Survey Download Page - bit.ly/SO-Survey-Download
Datetime Formatting Codes - bit.ly/python-dt-fmt
Pandas Date Offset Codes - bit.ly/pandas-dt-fmt
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python #Pandas

Пікірлер: 413

  • @coreyms
    @coreyms4 жыл бұрын

    Hope you all are all staying safe! In this video we'll be learning a lot about working with dates and time-series data in Pandas, and also look at doing some basic plotting. In the next video, we'll be learning how to load in data to Pandas from different (Excel, JSON, SQL, etc). Let me know if there is anything else you'd like me to cover in the Pandas series. I will likely be taking a break from this series after the next two videos are released just so I can focus on some different topics.

  • @kaaaaasraa49563

    @kaaaaasraa49563

    4 жыл бұрын

    Hey Corey Will you be able to cover some machine learning libraries like scikit learn,tensorflow,...? Because matplotlib and pandas that you have covered so far is related to machine learning and we can put this libraries into practical

  • @coreyms

    @coreyms

    4 жыл бұрын

    @@kaaaaasraa49563 I'll do my best. It's a very large topic to cover, so I've been a bit intimidated to tackle such a large course, but I know many people are wanting that, so I'll do my best to start working on something soon

  • @zahash1045

    @zahash1045

    4 жыл бұрын

    Hey guys checkout dfcleaner package on pypi

  • @kulpreetsingh9064

    @kulpreetsingh9064

    4 жыл бұрын

    Hey Corey, i was wondering if you could help do a complete EDA on one dataset ,kaggle or from anywhere in which you could cover the entire operations that we've learnt in one complete tutorial video with like a real world dataset. That could be like the end of this series video or something.

  • @loves_running5860

    @loves_running5860

    4 жыл бұрын

    Please help with numpy

  • @amazing-graceolutomilayo5041
    @amazing-graceolutomilayo50414 жыл бұрын

    I bless the day I came across your channel

  • @anubhavtomar1384
    @anubhavtomar13844 жыл бұрын

    3:50 convert to datetime using to_datetime 7:45 parse dates while loading data from csv 11:20 using day_name on whole series using dt class 12:20 create column of dayname 13:20 min and max methods on datetime series 15:00 filtering by dates as string 17:20 filter by to_datetime 18:40 set date as index 19:21 filter data by just passing the date in brackets 20:05 using a slice to get specific dates data 21:00 calculating average of a slice(timeframe) 22:05 getting max value of a column on a given day 23:50 resampling(breaking down by days) a whole column into a new variable 27:00 plotting with matplotlib in pandas 28:28 resampling df with multiple columns 30:55 using agg to apply different function on different columns while resampling

  • @mas7850

    @mas7850

    4 жыл бұрын

    Would it be possible for you to tell me how can I download ETH_1h.csv file? I found just row data on bit.ly/Pandas-10. Thanks in advance.

  • @lakshitakamboj198

    @lakshitakamboj198

    2 жыл бұрын

    😊

  • @gersonbronstein4664

    @gersonbronstein4664

    5 ай бұрын

    Wow! Thk you very much! I appreciated a lot!

  • @larc99
    @larc994 жыл бұрын

    For all those getting the following error: *FutureWarning: The pandas.datetime class is deprecated and will be removed from pandas in a future version. Import from datetime module instead.* Just do this: *from datetime import datetime* and change the *pd.datetime.strptime()* to: *datetime.srtptime()* and it should work the same.

  • @mrrohitnayak1

    @mrrohitnayak1

    3 жыл бұрын

    I used the following import datetime as dparser d_parser = lambda fn : dparser.datetime.strptime(fn, '%Y-%m-%d %I-%p') this also worked. is there any advantage of your method over mine ?

  • @alenjose3903

    @alenjose3903

    3 жыл бұрын

    @@mrrohitnayak1 its the same thing, u just named datetime as dparser, His code would call datetime.datetime.strptime() and yours call dparser.datetime.strptime()

  • @mrrohitnayak1

    @mrrohitnayak1

    3 жыл бұрын

    @@alenjose3903 any advantage in using his method over mine or vice versa

  • @alenjose3903

    @alenjose3903

    3 жыл бұрын

    @@mrrohitnayak1 no its the same, u can name it anything you want.

  • @Iris-fp9vo

    @Iris-fp9vo

    2 жыл бұрын

    Consider changing 'datetime.srtptime()' to 'datetime.strptime()'

  • @ste9240
    @ste92404 жыл бұрын

    Thanks a lot for this whole series Corey!! I've watched 3/4 other tutorials between youtube and other platforms and yours were the best by far, especially due to the fact that I'm from Italy so it was easier to follow your explanations step by step I can't wait for your plotting with Pandas tutorials too, those are gonna be pretty useful! Have a nice day a stay safe ;)

  • @next848484
    @next8484844 жыл бұрын

    Hi Corey, thank you so much for taking the time and putting this series together. This is one of the most structured series on panda on the web. I feel confident in pandas after watching the series. We would love to see something similar on the NumPy. Please, Corey...put together a Numpy series for us.

  • @lingen2193
    @lingen21934 жыл бұрын

    While there are already other excellent pandas tutorials on KZread your videos IMHO stand out for their carefully crafted examples, clarity of explanation, information density and relevance to practical applications. I'd really love this series to be continued and cover some of the more advanced topics.

  • @DavidChigbo
    @DavidChigbo2 ай бұрын

    You taught me pandas completely free of charge. Thank you, sir.

  • @void_invoker
    @void_invoker4 жыл бұрын

    My man Corey on youtube dropping bangers. Thanks man. Amazing content.

  • @ashishdeora8522
    @ashishdeora85223 жыл бұрын

    The concept of resample is so damn crazy!!! I struggle so much in other systems with this kind of aggregation and it's easy like nuts in pandas... Corey, you are great!

  • @electromorphous9567
    @electromorphous95674 жыл бұрын

    Right now I'm learning flask from your playlist and it's freaking amazing!

  • @piyushkonher8405
    @piyushkonher84054 жыл бұрын

    this whole series is so beautifully explained that if one is little bit aware of python and its syntax whole series can be watched without volume .

  • @ZsoltPal23092011
    @ZsoltPal23092011 Жыл бұрын

    These are the most developed, best explained videos on how to use pandas - thank you Corey for putting these together!

  • @MrSubWright
    @MrSubWright9 ай бұрын

    Also to get the mean for resampling, the default for the mean function was changed. So to get the weekly resampling at around 30:05 of the video: df.resample('W').mean() will give an error do this instead: df.resample('W').mean(numeric_only=True)

  • @sahilmehra290

    @sahilmehra290

    9 ай бұрын

    where to download this time series data please

  • @hermancoutinho
    @hermancoutinho2 жыл бұрын

    Thank you Corey for the wonderful tutorials. No paid courses can come close to the way you present the depth of the concept. Thank you for making it free and a big thank you for keeping up the good work.

  • @mahmoudgamal9835
    @mahmoudgamal98354 жыл бұрын

    Yesterday i was searching for any tutorial that explains dates and times in pandas and i couldn't find a good material Thanks man

  • @LegendaryGamer-px9dp
    @LegendaryGamer-px9dp5 ай бұрын

    For anyone getting error in the first part of the video, this is what worked for me d_parser = lambda x: pd.to_datetime(x, format='%Y-%m-%d %I-%p') df = pd.read_csv('data/ETH_1h.csv', parse_dates=['Date'], date_parser=d_parser)

  • @rafabws

    @rafabws

    4 ай бұрын

    or pass the date format directly df = pd.read_csv("data/ETH_1h.csv",parse_dates=['Date'],date_format = "%Y-%m-%d %I-%p")

  • @user-testo21347

    @user-testo21347

    3 ай бұрын

    @@rafabws for dfx.loc['2020-01':'2020-02'] , I get KeyError: 'Value based partial slicing on non-monotonic DatetimeIndexes with non-existing keys is not allowed.; What to do with it? plz help

  • @barissucuoglu

    @barissucuoglu

    Ай бұрын

    ​@@user-testo21347 I was getting same error too and I believe I found the solution. For some reason our indexes are not in order. For this reason, if we sort our indexes by writing the code dfx.sort_index(inplace=True) before writing the code dfx.loc['2020-01':'2020-02'], we get rid of the error.

  • @barissucuoglu

    @barissucuoglu

    Ай бұрын

    @@user-testo21347 I was getting same error too and I believe I solved it. For some reason our indexes are not in order. For this reason, if we sort our indexes by writing the code dfx.sort_index(inplace=True) before writing the code dfx.loc['2020-01':'2020-02'], we get rid of the error.

  • @Davidkiania
    @Davidkiania4 жыл бұрын

    This is the only channel I can’t wait for the new video to drop. Two weeks and waiting but who’s counting. ☺️

  • @artygecko7429
    @artygecko74299 ай бұрын

    To anyone getting the message that 'date_parser' is deprecated and will be removed in a future version... You no longer need to pass in a function, just the date string formats in the argument date_format='%Y-%m-%d %I-%p' example: df = pd.read_csv('ETH_1h.csv', parse_dates=['Date'], date_format='%Y-%m-%d %I-%p')

  • @gwanghyeongim768
    @gwanghyeongim7684 жыл бұрын

    I learnt so much from this single video. Thank you Corey

  • @timstark6744
    @timstark67444 жыл бұрын

    Great job Corey! Thank you!

  • @aatt3209
    @aatt32094 жыл бұрын

    I really appreciate your detailed explanation on the errors, which help us to select the right corrective action to take. Love your videos.

  • @rockeyvalley
    @rockeyvalley4 жыл бұрын

    Another great video Corey. Keep up the good work!!!

  • @benjamindeporte3806
    @benjamindeporte38064 жыл бұрын

    Very, very, very good. The accurate and straightforward explanations are supported by great examples. Big thanks.

  • @enrichomsrivera3637
    @enrichomsrivera36372 жыл бұрын

    That's great Corey !! The best lesson about Time series, ever.

  • @zio.eza25
    @zio.eza25 Жыл бұрын

    I learn through this video in 2023 as a new entry-level data analyst and non-native English. It's still relevant and lite but packed, especially for the `.resample()` method. It saves my time compared to using `.groupby()`. In addition, we need to keep in mind indice filtering. It's better to use `.loc[]` to avoid the deprecation issue. Thank you, Corey Schafer. Your channel is such a gem!

  • @tinylittleanj2
    @tinylittleanj23 жыл бұрын

    Corey this series is fantastic, thank you!

  • @Dark16Force
    @Dark16Force4 жыл бұрын

    Oh Corey, you legend! Thanks mate, this is some great stuff.

  • @PrateekTrivedi6
    @PrateekTrivedi62 жыл бұрын

    You are a great teacher, many thanks for putting in all the effort and time in creating such a great series :)

  • @dentupul
    @dentupul4 жыл бұрын

    Gave a thumbs up before even started watching the tutorial..and I'm not disappointed at all. Keep up the good work Corey!!! BTW you are the only KZreadr getting likes from me.

  • @nikhil1303
    @nikhil13034 жыл бұрын

    Hi Corey..I have referred to various resources to learn Pandas properly on KZread. And your tutorials are the best I could find. And looking forward to learn more from your matplotlib tutorials. Thanks for creating top class content!!

  • @shreyashkashyap
    @shreyashkashyap Жыл бұрын

    Extremely useful. Thanks for the video Corey! You have my gratitude.

  • @latenines
    @latenines2 жыл бұрын

    This is the best episode from the series, well done

  • @disko.kommando
    @disko.kommando4 жыл бұрын

    Thank you again Corey!!

  • @tassoskat8623
    @tassoskat86233 жыл бұрын

    This was an absolute masterpiece!! Thank you so much. I hope you are good and safe

  • @ScriptsNerd
    @ScriptsNerd3 жыл бұрын

    OMG!!! You are awesome Corey. I learned a lot from your videos!

  • @Terence818
    @Terence8183 жыл бұрын

    pandas plotting will be useful and intesting! looking forward to it! Thanks Corey!

  • @djuka8121
    @djuka81214 жыл бұрын

    I always give you a thumbs up before i even watch the video! Will you introduce us to machine learning in the near future?

  • @charlesmiele2135
    @charlesmiele21352 жыл бұрын

    This is so in depth I love it thank you!

  • @kohyuze
    @kohyuze4 жыл бұрын

    There should be a mega-like button for this. Thank you so much!

  • @puffziggy7330
    @puffziggy73304 жыл бұрын

    Since I stumbled on Corey Schafer videos, it has become my favourite KZread Channel

  • @dakshaudawatta8219
    @dakshaudawatta82194 жыл бұрын

    Thanks a lot for this pandas series Corey ♥️.

  • @spicer41282
    @spicer412824 жыл бұрын

    Please show more *errors and its corrections* for future vids. The fixes are really beneficial! Thanks for recording, editing, uploading and sharing! 👍

  • @pookpratch
    @pookpratch3 жыл бұрын

    I really like how you explain things so clearly. Super helpful for my project. Thank you so much!

  • @jubayerhossain8812
    @jubayerhossain88124 жыл бұрын

    Great! I love your lectures.

  • @ioannisnikolaospappas6703
    @ioannisnikolaospappas6703 Жыл бұрын

    Thanks Corey! Your videos are always lit! 😁✌️

  • @mapa5000
    @mapa5000 Жыл бұрын

    What a detailed video !! Thank you man !!! 🤝

  • @puffziggy7330
    @puffziggy73304 жыл бұрын

    Awesome stuff as always

  • @kanimozhipanneerselvam3017
    @kanimozhipanneerselvam30173 жыл бұрын

    I'm happy that I found a Awesome channel to learn Python for Data Science Easily!!!! Very Nice and Crystal Clear Explanation!!👌🙂

  • @tumul1474
    @tumul14743 жыл бұрын

    Amazing tutorials man ! thank you so much

  • @robcz3926
    @robcz39264 жыл бұрын

    great job Corey, I was going to go through Wes McKinney's book but looking at the pandas section I realized that I already know most of it by now form your series. Pls do the data plotting soon! ;)

  • @swarnachoppella388
    @swarnachoppella388 Жыл бұрын

    Thank you for the detailed explanation

  • @kaifahmad4131
    @kaifahmad41313 ай бұрын

    Best tutorial series for pandas ever❤❤❤

  • @patrickwheeler1979
    @patrickwheeler1979 Жыл бұрын

    And yet another great lesson. Thanks

  • @michaelmitchell155
    @michaelmitchell1558 ай бұрын

    I used this video to backtrack over some material that I wasn't sure of. This was a great video as is your other instructional videos. Thanks so much.

  • @tiagomarcilio1
    @tiagomarcilio1 Жыл бұрын

    Man...you really rock! Thanks a lot for that!

  • @siddharthmodi5908
    @siddharthmodi59083 жыл бұрын

    Your every video is soo nice and perfect. The explanation is very friendly and in a proper sequence. Your channel works for me as a one-stop-shop. Thank you soo much man.❤️❤️ Love from India 🇮🇳

  • @nickyhong28
    @nickyhong283 жыл бұрын

    thank you Corey for making this video

  • @misseghe3239
    @misseghe32392 жыл бұрын

    Thank you thank you thank you, Finally found the help that i needed!

  • @imad_uddin
    @imad_uddin3 жыл бұрын

    This was really helpful. Thanks!

  • @vishaalranjan1783
    @vishaalranjan17834 жыл бұрын

    Hi Corey! Your series on pandas is really informative and helpful. Can you make a similar series for numpy? I believe that's a topic that will be of interest to many of your viewers.

  • @dnyaneshwar53
    @dnyaneshwar532 жыл бұрын

    All I can say you are awesome. The way you explained 😍✌️✌️✌️✌️. You have the best play list for pandas on web. Your efforts are truly appreciated 👍👍👍👍👍👍

  • @kavehyarohi2886
    @kavehyarohi28864 жыл бұрын

    corey man, i feel obligated to say thank you , aaaaaaaaaaaaaaaaaand a big well done sir.

  • @gordonmorrow6945
    @gordonmorrow69454 жыл бұрын

    Fantastic series! Thank you for providing this awesome content. I have been using Pandas quite a bit lately to process data, one thing I am struggling with and would really find helpful would be a video on taking these Pandas notebooks and functions and converting them into actual Python apps that can be reused on other projects. Pandas can really be like magic sometimes and being able to pass data into a Python app that could apply these functions would be extremely powerful, I have yet to find any good tutorials or reading on this subject, one from the master would be greatly appreciated!!

  • @moushumitamanna
    @moushumitamanna4 жыл бұрын

    You are the best teacher. period

  • @dasbcutpaste6473
    @dasbcutpaste6473 Жыл бұрын

    This has been beyond useful! Thank you.

  • @easydatascience2508

    @easydatascience2508

    Жыл бұрын

    Hei, welcome to my playlists too, Python and R, downloadable source files (see video description)

  • @17avskadoo
    @17avskadoo3 жыл бұрын

    again and again awesome information

  • @ketanbutte3497
    @ketanbutte34974 жыл бұрын

    just 11 minutes in the video, i hit the like button as hard as i can !!

  • @antonywill835
    @antonywill8353 жыл бұрын

    Always the best, wonderful.

  • @drhastings
    @drhastings4 жыл бұрын

    Thank you Sir for sacrificing your precious time to teach the World. We appreciate you . l Appreciate You.

  • @mByyurt
    @mByyurt4 жыл бұрын

    I want to point out something. I like your videos. There is nothing boring about them. But I do not have much time so I watch them at 2x. Your normal talking speed is not slow but very clear so I can easily understand you at 2x too.

  • @Dara-lj8rk
    @Dara-lj8rk4 жыл бұрын

    Well done! I didn't know that I can pass in a dict in agg. Always passed in a list and then selected the column-aggregation tuples that I needed, which is quite resource intensive and hard to read. Also I did not know I could make datetime comparisons to a string. Thank you.

  • @AbdAlkareemAlBadawi
    @AbdAlkareemAlBadawiКүн бұрын

    You're my savior I was searching for video as this thank you.

  • @icehank
    @icehank3 жыл бұрын

    thank so much!!! you help me a lot!!!!

  • @RK_97
    @RK_974 жыл бұрын

    Fantastic series on Pandas. I have no words to express how i am thankful to you for this series. You are a great teacher. I am yet to check on the 11th video on this series and up next to the Matplotlib series (definetely). You are awesome. A request, could you please plan to do Numpy series as well.

  • @dennisamaya9892
    @dennisamaya98923 жыл бұрын

    This Video was sent by the Data Science Gods. Thank you so much

  • @ShaiVibes
    @ShaiVibes4 жыл бұрын

    Thank you. This is very useful.

  • @wasirizvi2437
    @wasirizvi24374 жыл бұрын

    As usual your videos are great ! You explain things very clearly. Please start videos on Machine Learning and Artificial Intelligence soon. Earnest request !

  • @user-vd1rj7hb1o
    @user-vd1rj7hb1o6 ай бұрын

    I loved the point Corey made about how much easier it is to use date as your index, however while following along I got a warning this warning: FutureWarning: Indexing a DataFrame with a datetimelike index using a single string to slice the rows, like `frame[string]`, is deprecated and will be removed in a future version. Use `frame.loc[string]` instead.

  • @Rocklee46v
    @Rocklee46v4 жыл бұрын

    I watched this video when the likes for this video are 999 and I hit like right away to make it 1K, because I believe Corey's content!

  • @gilmarflorencio9216
    @gilmarflorencio9216 Жыл бұрын

    Excelente explicação, muito obrigado!

  • @HabibAlSaki
    @HabibAlSaki4 жыл бұрын

    Very well-explained. Thanks for this. I am requesting you to make a video on multi index in Pandas.

  • @the-ghost-in-the-machine1108
    @the-ghost-in-the-machine1108 Жыл бұрын

    Excellent!

  • @frankservant5754
    @frankservant57543 жыл бұрын

    Thanks for the tutorial

  • @lukeshepherd2342
    @lukeshepherd23429 ай бұрын

    I got an error with the lambda function trying to parse the dates while loading from csv. The error stated pandas no longer supports pd.datetime. After checking the comments I tried @larc99's suggestion but still got an error as it was expecting a string rather than a function for the format. What gave the same output and I think is much simpler (without the lambda function) turned out to be: df = pd.read_csv('data/ETH_1h.csv', parse_dates=['Date'], date_format='%Y-%m-%d %I-%p')

  • @thulasirao9139
    @thulasirao91393 жыл бұрын

    excellent video with details. Thank you

  • @wer_gumizz1012
    @wer_gumizz10124 жыл бұрын

    Thanks for you video.

  • @tau4759
    @tau4759 Жыл бұрын

    You’re the best 👍

  • @anurasenarathna1703
    @anurasenarathna17032 жыл бұрын

    Good Series. Thank you very much.

  • @P3ace1oveUn1ty
    @P3ace1oveUn1ty2 жыл бұрын

    Loving this series and have learned a lot. The prices of ETH in this video, wow!

  • @RAJASEKARCMR

    @RAJASEKARCMR

    9 ай бұрын

    டேmn true. $200 vs $4900 at peak and $1700 now

  • @stayshikshit
    @stayshikshit3 жыл бұрын

    @CoreySchafer, you're awesome. Loved your quality video content. Your work is fabulous. I'd really like to see DevOps related content if it comes under your scope. Thanks 👍

  • @calwheel5389
    @calwheel53894 жыл бұрын

    Great Vid thanks

  • @Soulfulreader786
    @Soulfulreader7862 жыл бұрын

    Pandas is so easy to work on after seeing this vid. Wish my coaching teacher taught me this simpler way

  • @gisleberge4363
    @gisleberge43632 жыл бұрын

    Good example and coverage 👍🙂

  • @baidris
    @baidris2 жыл бұрын

    Contenu plein de connaissance. Merci

  • @aaronglenn7764
    @aaronglenn77644 жыл бұрын

    Hi Corey, Thank you so much for the videos! I was wondering when you are going to come out with the Pandas plotting series you mention? Thanks again!

  • @RlxRlx1
    @RlxRlx13 жыл бұрын

    Thanks a lot!

  • @habrom1000
    @habrom10002 жыл бұрын

    great tutorial

  • @KevinTempelx
    @KevinTempelx3 жыл бұрын

    Thank you!

  • @RishiSaikia
    @RishiSaikia3 жыл бұрын

    At 20.08, calling df['2019'] didn't work for me. Gave an 'Assertion Error'. df.loc['2019'] worked though.

  • @nesrinebelkadi7702

    @nesrinebelkadi7702

    3 жыл бұрын

    Same here !