Тёмный

Matplotlib Tutorial (Part 2): Bar Charts and Analyzing Data from CSVs 

Corey Schafer
Подписаться 1,3 млн
Просмотров 339 тыс.
50% 1

In this video, we will be learning how to create bar charts in Matplotlib.
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 how to create bar charts in Matplotlib. Bar charts are great for visualizing your data in a way where you can clearly see the total values for each category. We'll learn how to create basic bar charts, bar charts with side-by-side bars, and also horizontal bar charts. We will also learn how to load our data from a CSV file instead of having it directly in our script. Let's get started...
The code from this video (with added logging) can be found at:
bit.ly/Matplotlib-02
CSV Tutorial - • Python Tutorial: CSV M...
✅ 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 #Matplotlib

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

 

26 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 347   
@Sharmapawan98
@Sharmapawan98 5 лет назад
Who needs python docs when you have such an amazing teacher
@seanli75
@seanli75 3 года назад
True:
@niteshprajapat7918
@niteshprajapat7918 3 года назад
Exactly Brother
@JoshKonoff1
@JoshKonoff1 3 года назад
Where is the CSV for this? I don't see it in the description. Thank you!
@SimonYells
@SimonYells 2 года назад
True
@OT-tn7ci
@OT-tn7ci 2 года назад
the teacher
@coreyms
@coreyms 5 лет назад
I hope everyone finds this video helpful. The next video of the series will be posted tomorrow at the same time. The next video will cover how to create pie charts. I'd like to thank Brilliant for sponsoring this series. If you'd like to check them out then you can sign up with this link and get 20% off your premium subscription: brilliant.org/cms
@dhananjaykansal8097
@dhananjaykansal8097 5 лет назад
As usual lovely!!!!!!!
@tamasasztalos7484
@tamasasztalos7484 5 лет назад
It's a great tutorial; the only thing I was missing is to add total values on the top of each bar charts (can be trickier for stacked bar chart)
@ishanpand3y
@ishanpand3y 4 года назад
Thank you, sir, for providing top-class tutorials for free.
@JuniorDIEKA
@JuniorDIEKA 4 года назад
Hello Corey! Please can you advise: 1. how did you the clean the data within the column " LanguageWorkedWith" so that you can generate this clear data? 2. After I have split it and save it to another csv file a part from the main, the is the output: [(" 'JavaScript'", 53020), (" 'HTML/CSS'", 39761), (" 'Java'", 29863), ("['Bash/Shell/PowerShell'", 28340), (" 'SQL']", 28178), (" 'Python'", 26185), (" 'PHP'", 20394), (" 'SQL'", 19094), (" 'TypeScript']", 16091), ("['HTML/CSS'", 15322)] [Finished in 33.6s] 3. According the below output , how will I do so that it can bring the sum exact of the occurrence of the languages as it look like not doing it? Thank you,
@JoshKonoff1
@JoshKonoff1 3 года назад
Where is the CSV for this? I don't see it in the description. Thank you!
@MrBuion
@MrBuion 4 года назад
These series is much better than the curses in Udemy I paid for. Thank you very much.
@DendrocnideMoroides
@DendrocnideMoroides 3 года назад
what "curses"
@iscoto4914
@iscoto4914 2 года назад
@@DendrocnideMoroides wannabe savage
@ishanpand3y
@ishanpand3y 4 года назад
In case you don't know, the shortcut for 8:13 in jupyter notebook is *Ctrl + left mouse click* on the different lines one by one. You can write at different lines at the same time.
@jaxnaur218
@jaxnaur218 2 года назад
Nice! Thanks form 2years later!
@jeffery_tang
@jeffery_tang 2 года назад
alt + left mouse in vs code
@damalkkoklannou1620
@damalkkoklannou1620 7 месяцев назад
thanks u @@jeffery_tang
@bmwmhamam
@bmwmhamam 4 года назад
No body teaches like you. You are the best. Amazing delivery of information, truly useful tutorials. Thank you so much.
@TheShubham67
@TheShubham67 4 года назад
This series with pandas one has taken my skills to a new level.
@sunshadow9704
@sunshadow9704 2 года назад
Corey, you are great teacher. You have rare ability to explain calmly. Much appreciating your efforts.
@lalu225
@lalu225 5 лет назад
Excellent tutorial Corey! Real life stuff and practical, including the use of Counter. It's important to show these data preparation steps. Very helpful indeed, thank you.
@Ghasakable
@Ghasakable 5 лет назад
Man, you are awesome, everything I have learned about python started from your channel, I wish you the very best all success, as you make everyone happy, keep up the excellent work, we all heavily rely on you.
@coreyms
@coreyms 5 лет назад
Thanks! That's very kind of you.
@KienDoanTrung168
@KienDoanTrung168 5 лет назад
such a great Python instructor with an angelic voice. Thank you so much 😊
@fangshizhu9383
@fangshizhu9383 3 года назад
At 8:12, when you selected multiple locations and simultaneously type the same code to multiple lines, my world just expanded!
@abhishek_raj
@abhishek_raj 3 года назад
Right from reading data from a csv file to plotting it, you helped a lot of people.
@apoorvwatsky
@apoorvwatsky 5 лет назад
23:40 here's that one liner if anybody's interested. Personally, I like this more. languages, popularity = map(list, zip(*language_counter.most_common(15)))
@costasvas341
@costasvas341 4 года назад
Really nice! Could you please explain what the "*" symbol does?
@paklong2556
@paklong2556 4 года назад
nice
@jg9193
@jg9193 4 года назад
Or just: list(zip(*language_counter.most_common(15))). Map is unnecessary as list() automatically maps over an Iterable
@corben3348
@corben3348 4 года назад
@@jg9193 but if you don't use map(list, iterable) then languages and popularity will be tuples so you cannot use reverve() for the rest of the tutorial. Or languages, popularity = [list(e) for e in zip(*language_counter.most_common(15))] without map
@jg9193
@jg9193 4 года назад
@@corben3348 Fair point, I didn't think of that. That said, he could just do languages[::-1] instead of languages.reverse() to reverse a tuple Then again, using list() would even be unnecessary if he did that
@miosz952
@miosz952 4 года назад
The great thing about your tutorials is that despite main topic, you learn a lot useful tricks, modules etc.
@ahmedskasmani
@ahmedskasmani 4 года назад
Amazing content Corey. The way you simplify the material and explain is awesome, many thanks. Can you please also do a video showing your setup and how you make video's. Thanks !!!
@djadamkent
@djadamkent 5 лет назад
Another great video, thank-you. A Pandas series of videos would be awesome!
@ItzSenaCrazy
@ItzSenaCrazy 5 лет назад
What I really like is your videos, Corey. I can learn Python and English ;D Thanks!!
@storiesshubham4145
@storiesshubham4145 2 года назад
I can't express how amazing this video is. What a great teacher you are. 🔥🔥
@shadowmasked7188
@shadowmasked7188 Год назад
Thank you very much bro, Greetings from Azerbaijan.
@LashaGoch
@LashaGoch 3 года назад
This is gold! Thank you very much for doing this, you have incredible talent to explain complicated stuff in an easy manner, keep up good work :)))
@randiarisman2419
@randiarisman2419 4 года назад
Another great video form you, Corey. Thank you, you made my day everyday!!
@redferne01
@redferne01 5 лет назад
Thank you for your work. I enjoy every lesson.
@fourdaysdead
@fourdaysdead 5 лет назад
thank you very much, very clear and straight to the point!
@dgh25
@dgh25 Год назад
Your videos are just sprinkled with little golden nuggets! I love it ❤
@58_yesilgul
@58_yesilgul 6 месяцев назад
What a perfect lesson, fast and insightful pieces of knowledge...
@shazkingdom1702
@shazkingdom1702 5 лет назад
This is the best Corey; Thank you very much from my 🧠 and ❣
@rnytpl
@rnytpl 3 года назад
Thank you man, appreciate the effort and time you've put in creating such amazing content as these.
@androkranjcevic1988
@androkranjcevic1988 3 года назад
Really nice work over here, the most important man on youtube for me.
@dalanxd
@dalanxd 3 года назад
Corey Schafer saves my life once again... Deep gratitude for your work, man!
@minghaotao6259
@minghaotao6259 5 лет назад
Thank you for sharing your knowledge!
@mohammedismail308
@mohammedismail308 5 лет назад
Thanks a lot Corey. Really your videos are endless treasure. Just a way for plotting bar charts for more than one dataset on the same plot without need to numpy. Just use built-in map function. width = 0.25 #Width of bar plt.bar(list(map(lambda x: x-width/2, age_x)), salaries1, color = 'k', width = width) plt.bar(list(map(lambda x: x+width/2, age_x)), salaries2, color = 'r', width = width)
@tongliu1076
@tongliu1076 4 года назад
Great video as always! Really helpful for detailed explanation.
@luiggitello8546
@luiggitello8546 7 месяцев назад
This is the best content on RU-vid, thank you for so much
@borhansiddiki7079
@borhansiddiki7079 4 года назад
I think your videos are more understandable than rest of the youtube channels
@gamengine1176
@gamengine1176 4 года назад
Very helpful video. The pandas method is much simpler and easier to understand. Thanks Corey!
@abhishek_raj
@abhishek_raj 3 года назад
You explain things really well, kudos!
@alexanderten5497
@alexanderten5497 5 лет назад
Thank you very much.its a great tutorial as always
@pratikarai8115
@pratikarai8115 4 года назад
Your explanation is awesome...thank you so much ...A great teacher for a lifetime...
@introduction_official6547
@introduction_official6547 4 месяца назад
Very informative video, good job Mr Corey
@brumarul7481
@brumarul7481 3 года назад
This is pure Gold .
@shuklarahul17
@shuklarahul17 4 года назад
As you mentioned Zip can also be used language = cnt.most_common(10) language.reverse() language_X, language_Y = list(zip(*language)) plt.barh(language_X, language_Y)
@dhairyaoza5422
@dhairyaoza5422 3 года назад
thank you so much sir,really glad i found ur playlist and didn't waste time on other platforms
@Linshark
@Linshark 2 года назад
I just came across this series of videos. They are extremely good :-)
@lillyclive2641
@lillyclive2641 4 года назад
Such a great help, thankyou so much!
@SandeepChaudhary-vx9zy
@SandeepChaudhary-vx9zy 4 года назад
Great explanation...thanks a lot Corey sir
@giuseppeceravolo93
@giuseppeceravolo93 4 года назад
Thank you so much for your hard work! You are a great teacher and your video tutorial represent a valuable resource :)
@franklinlima2571
@franklinlima2571 4 года назад
Great video! Thank you man
@Anon282828
@Anon282828 2 года назад
thank you for always showing the clear code before abbreviating
@DidaKusAlex
@DidaKusAlex 2 года назад
great tutorial! the best!! thanks for teaching us!
@muzaianghanem5644
@muzaianghanem5644 4 года назад
That's true......you are an amazing teacher. This was very helpful
@dhssb999
@dhssb999 Год назад
best matplotlib tutorial ever!
@thebuggser2752
@thebuggser2752 8 месяцев назад
Another great video. Thanks!!
@emmanueljimawo5595
@emmanueljimawo5595 5 лет назад
Great videos. I'm so grateful...
@cooldudesjce
@cooldudesjce 4 года назад
Amazing Tutorials Thanks soo much !
@PaoloCondo
@PaoloCondo Год назад
Thank you for the series of video! :)
@akashdeepchauhan5
@akashdeepchauhan5 3 года назад
You're making machine learning interesting, thank you
@brucegwon
@brucegwon 3 года назад
This is the best fantastic lecture for the relation of Python and Pandas I've ever seen!!!!!!!!!!!!!! Xie Xie!!!
@nicholasmaloof8378
@nicholasmaloof8378 5 лет назад
2 weeks later and still not a single dislike on this video
@eliesawan9513
@eliesawan9513 3 года назад
you are amazing, waiting for your data science ( ML, AI ) course...... THANKS A LOT!
@DeepakKumar-uz4xy
@DeepakKumar-uz4xy 5 лет назад
thank you professor. love from india. u know what i dont like to read those documentation. when i saw your videos.
@MagnusAnand
@MagnusAnand 2 года назад
I can't believe we need this hack to make a bar chart. Great video.
@michaelren2821
@michaelren2821 3 года назад
great tutorial, thanks
@mallusreddy
@mallusreddy 5 лет назад
Thank you so much.. It's a great vedio....
@ericfricke4512
@ericfricke4512 4 года назад
Programming is so fun.
@Martin-ij2fp
@Martin-ij2fp 3 года назад
Great video!
@luiscesar_agais
@luiscesar_agais 2 года назад
Very nice your explanations. Congratulations.
@ondereren5003
@ondereren5003 3 года назад
Amazing video !
@Coney_island23
@Coney_island23 2 года назад
thank you!!!! you ar an excellent teacher
@markkennedy9767
@markkennedy9767 9 месяцев назад
Thanks for this. Great lesson. As you say, creating multiple bars seems extraordinarily hacky. I would have thought this would be easily dealt with by a plotting library
@SahilKhan-rv9xb
@SahilKhan-rv9xb 3 года назад
for those wondering how to obtain the CSV file, once you've clicked on it and you see all of the data in your web browser, just right click and say save as
@Alejandro-ry9ny
@Alejandro-ry9ny 3 года назад
jaja that was very useful, Thanks!
@shashankbanakar8766
@shashankbanakar8766 2 года назад
Thanks so much!
@KC-rl8ub
@KC-rl8ub 5 лет назад
hi Corey....god bless you
@rajivswargiary1536
@rajivswargiary1536 5 лет назад
Great tutorial sir
@edcoughlan5742
@edcoughlan5742 5 лет назад
These videos are great! Coming from R (and ggplot) I was a tad skeptical that Python could emulate R when it came to data viz, but I stand corrected.
@kabongontumba9492
@kabongontumba9492 3 года назад
You're right
@akunnaemeka395
@akunnaemeka395 2 года назад
thank you Brilliant for supporting Corey
@AbubakerMahmoudshangab
@AbubakerMahmoudshangab 2 года назад
Corey. Million thanks bro
@VishalSharma-rn7mt
@VishalSharma-rn7mt 4 года назад
Great, amazing video
@micheliwrmg
@micheliwrmg Год назад
sad fact, if you want to open csv file in PYcharm , you have to pay for PYcharm Professional(~$230) :( btw you are the best teacher I've ever seen
@mindbodysoulsculpt6479
@mindbodysoulsculpt6479 4 года назад
Great Matplotlib tutorial. But I feel like this is where Pandas also really comes to play, we can use sep = ; inside of the read_csv function instead of creating a custom function. Also, using iloc and loc for indexes and many more awesome built in functions
@hayetchekired462
@hayetchekired462 3 года назад
great instructor
@gurukirans266
@gurukirans266 4 года назад
Thank you lot sir 😃
@karishmakaris7165
@karishmakaris7165 4 года назад
ty soo much .. yu are the best ..
@nowyouknow2249
@nowyouknow2249 5 лет назад
Wonderful! Thanks a lot CMS
@chrisray1567
@chrisray1567 5 лет назад
collins anele That probably won’t work because value_counts() won’t split the data at the semicolons, so “Python;JavaScript” would be one value instead of two.
@nowyouknow2249
@nowyouknow2249 5 лет назад
You are right. I just realised that.
@mamathakavety6529
@mamathakavety6529 Год назад
Please do a tutorial on numpy as well, it would be super helpful, by the way awesome content😁
@abhinav9561
@abhinav9561 3 года назад
Thanks man!!
@noway4715
@noway4715 4 года назад
Best of the best!
@manosmakris8308
@manosmakris8308 Год назад
You can also do this for geting the languages and popularity lists. languages = list(map(lambda x: x[0], language_counter.most_common(15))) print(languages) popularity = list(map(lambda x: x[1], language_counter.most_common(15))) print(popularity)
@rahil1575
@rahil1575 Год назад
you are a life saviour for people like me
@FerdinandCoding
@FerdinandCoding 4 года назад
thank you for python tutorial
@KumarGauravhi
@KumarGauravhi 3 года назад
Hi Corey, thank you for the wonderful session , I have stuck at this point with the last example :-import csv import numpy as np import pandas as pd from collections import Counter from matplotlib import pyplot as plt plt.style.use("fivethirtyeight") data = pd.read_csv('data.csv') ids = data['Responder_id'] lang_responses = data['LanguagesWorkedWith'] language_counter = Counter() for response in lang_responses: language_counter.update(response.split(';')) languages = [] popularity = [] for item in language_counter.most_common(15): languages.append(item[0]) popularity.append(item[1]) languages.reverse() popularity.reverse() plt.barh(languages, popularity) plt.title("Most Popular Languages") # plt.ylabel("Programming Languages") plt.xlabel("Number of People Who Use") plt.tight_layout() plt.show() ### I am getting an error like AttributeError: 'float' object has no attribute 'split' ...Please explain..
@johnjones5659
@johnjones5659 4 года назад
Thanks you and Brilliant
@SM-vu6fm
@SM-vu6fm 2 года назад
Counter() is the best thing I learned today
@Kralnor
@Kralnor 2 года назад
Fantastic video. Exactly the type of content that I was looking for to create beautiful bar graphs.
@harshman11
@harshman11 5 лет назад
I love Corey's videos*(infinite).
@gurukirans266
@gurukirans266 4 года назад
Tq sir This is for u sir while 2 < 3: print('thank you soo much')
@kerimabdul2263
@kerimabdul2263 4 года назад
great video.
@laurentb6563
@laurentb6563 4 года назад
Very inspiring
@rotrose7531
@rotrose7531 2 года назад
Thank you very much. Please, please come back!
@eduardosiqueirabonfim98
@eduardosiqueirabonfim98 3 года назад
Thanks!
@veenak108
@veenak108 4 года назад
@Corey Schafer .. I came up with below function which will handle the bar widths for multiple bar plots by itself. Just in case anybody wants to use it : ages_x = np.asarray([25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]) count = 5 width = 0.8/count def width_cal(position): shift = np.array([]) if count < 2: return ages_x if count % 2 == 0: for i in range(1, count, 2): shift = np.append(shift, (width/2 * i)) shift = np.sort(np.append(shift, np.negative(shift))) else: for i in range(0, count, 2): shift = np.append(shift, (width/2 * i)) shift = np.unique(np.sort(np.append(shift, np.negative(shift)))) shift = np.around(shift, decimals=3) return ages_x + shift[position] plt.bar(width_cal(0), dev_y, width=width, color='#444444', label="All Devs")
@oscarkiamba7690
@oscarkiamba7690 Год назад
The best in you tube .👏