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
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,
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.
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)))
@@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
@@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
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.
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
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)
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.
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 !!!
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)
@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")
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)
For PANDAS folks:- import pandas as pd from collections import Counter df = pd.read_csv('data.csv', index_col=['Responder_id']) language_counter = Counter() for response in df['LanguagesWorkedWith']: language_counter.update(response.split(';'))
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..
for unpacking counter.most_common(x) you can use: for a,b in counter.most_common(x) or for a,b in counter.items(): cause they are the same, they are a list of tuples, which is "zipped" already = meaning you can iterate of it simultaneously (a is tuple[0]. b is tuple[1]) I hope it helps you, yea you out there.
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
that feel when I paused tutorial to figure out how to extract languages and popularity from language_counter and later it turns out that you've done that exactly in the same way, lol
Corey, I went back to the documentation, and changed by code to ax=plt.subplot() ax.set_xticks(x_indexes) ax.set_xticklabels(ages_x) It worked, but I received a message : MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. warnings.warn(message, mplDeprecation, stacklevel=1)
We can not thank you enough..still thanks a ton Corey. I have an interesting observation @9.48. In the plt.xticks(...) method when I use the ticks and labels keywords it gives me AttributeError. It works when I pass the arguments without using keywords. Perhaps it has something to do with my Matplotlib version...
At 9:30 you correct the numbers of the x-axis with plt.xticks() Couldn't we just have circumvented that problem by saying x_indexes = np.array(ages_x) instead of x_indexes = np.arange(len(ages_x)) Since that would have given us an array with the original numbers that we could add/subtract the width to/from? Is there any benefit to the plt.xticks() solution (other than seeing how xticks work)?
I thought the exact same thing, why is he making his life more complicated than necessary? There is no problem with adding/subtracting offsets directly from the ages np.array, it just works. It makes it less hacky, too.
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
For the side by side bar plots, I found that using the plt.bar() args align='edge', align='center', and align='edge', along with width=-0.75, 0.5, 0.75 is easier than using numpy and specifying the tick labels.
Another great tutorial. Thank you. However, using a Jupyter Notebook, I am having a problem with plt.bar, plt.barh. The error I receive is "unsupported operand type(s) for -: 'str' and 'float'.
Who needs python docs when you have such an amazing teacher
True:
Exactly Brother
Where is the CSV for this? I don't see it in the description. Thank you!
True
the teacher
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
As usual lovely!!!!!!!
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)
Thank you, sir, for providing top-class tutorials for free.
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,
Where is the CSV for this? I don't see it in the description. Thank you!
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.
Nice! Thanks form 2years later!
alt + left mouse in vs code
thanks u
@@jeffery_tang
These series is much better than the curses in Udemy I paid for. Thank you very much.
what "curses"
@@DendrocnideMoroides wannabe savage
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)))
Really nice! Could you please explain what the "*" symbol does?
nice
Or just: list(zip(*language_counter.most_common(15))). Map is unnecessary as list() automatically maps over an Iterable
@@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
@@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
This series with pandas one has taken my skills to a new level.
At 8:12, when you selected multiple locations and simultaneously type the same code to multiple lines, my world just expanded!
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.
Thanks! That's very kind of you.
Corey, you are great teacher. You have rare ability to explain calmly. Much appreciating your efforts.
No body teaches like you. You are the best. Amazing delivery of information, truly useful tutorials. Thank you so much.
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
jaja that was very useful, Thanks!
Thanks so much!
Right from reading data from a csv file to plotting it, you helped a lot of people.
I think your videos are more understandable than rest of the youtube channels
such a great Python instructor with an angelic voice. Thank you so much 😊
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)
Thank you very much bro, Greetings from Azerbaijan.
Another great video, thank-you. A Pandas series of videos would be awesome!
The great thing about your tutorials is that despite main topic, you learn a lot useful tricks, modules etc.
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.
Corey Schafer saves my life once again...
Deep gratitude for your work, man!
2 weeks later and still not a single dislike on this video
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 !!!
I can't express how amazing this video is. What a great teacher you are. 🔥🔥
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)
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
What I really like is your videos, Corey. I can learn Python and English ;D
Thanks!!
Programming is so fun.
thank you Brilliant for supporting Corey
best matplotlib tutorial ever!
Very informative video, good job Mr Corey
@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")
Your videos are just sprinkled with little golden nuggets! I love it ❤
This is the best content on RUclips, thank you for so much
This is pure Gold .
Really nice work over here, the most important man on youtube for me.
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 :)))
What a perfect lesson, fast and insightful pieces of knowledge...
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)
thank you for always showing the clear code before abbreviating
Counter() is the best thing I learned today
I can't believe we need this hack to make a bar chart.
Great video.
Very helpful video. The pandas method is much simpler and easier to understand. Thanks Corey!
Thank you for your work. I enjoy every lesson.
Your explanation is awesome...thank you so much ...A great teacher for a lifetime...
thank you so much sir,really glad i found ur playlist and didn't waste time on other platforms
For PANDAS folks:-
import pandas as pd
from collections import Counter
df = pd.read_csv('data.csv', index_col=['Responder_id'])
language_counter = Counter()
for response in df['LanguagesWorkedWith']:
language_counter.update(response.split(';'))
That's true......you are an amazing teacher. This was very helpful
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.
You're right
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..
you are a life saviour for people like me
for unpacking counter.most_common(x) you can use:
for a,b in counter.most_common(x) or for a,b in counter.items():
cause they are the same, they are a list of tuples, which is "zipped" already =
meaning you can iterate of it simultaneously (a is tuple[0]. b is tuple[1])
I hope it helps you, yea you out there.
I just came across this series of videos. They are extremely good :-)
This is the best fantastic lecture for the relation of Python and Pandas I've ever seen!!!!!!!!!!!!!!
Xie Xie!!!
hi Corey....god bless you
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
Thank you man, appreciate the effort and time you've put in creating such amazing content as these.
Thank you very much. Please, please come back!
thank you very much, very clear and straight to the point!
Thank you for sharing your knowledge!
Great explanation...thanks a lot Corey sir
Great video! Thank you man
Another great video form you, Corey. Thank you, you made my day everyday!!
that feel when I paused tutorial to figure out how to extract languages and popularity from language_counter and later it turns out that you've done that exactly in the same way, lol
you are amazing, waiting for your data science ( ML, AI ) course...... THANKS A LOT!
Corey, I went back to the documentation, and changed by code to
ax=plt.subplot()
ax.set_xticks(x_indexes)
ax.set_xticklabels(ages_x)
It worked, but I received a message : MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
You're making machine learning interesting, thank you
You explain things really well, kudos!
This is the best Corey; Thank you very much from my 🧠 and ❣
Thank you very much.its a great tutorial as always
Great video as always! Really helpful for detailed explanation.
thank you professor. love from india. u know what i dont like to read those documentation. when i saw your videos.
we can also use the dictionary's keys() and values() for getting x and y axis. x_axis = list(dict.keys())
I jus found the python legend . Thank god
Another great video. Thanks!!
Thank you for the series of video! :)
Such a great help, thankyou so much!
Corey. Million thanks bro
great tutorial! the best!! thanks for teaching us!
thank you!!!! you ar an excellent teacher
Very nice your explanations. Congratulations.
We can not thank you enough..still thanks a ton Corey.
I have an interesting observation @9.48. In the plt.xticks(...) method when I use the ticks and labels keywords it gives me AttributeError. It works when I pass the arguments without using keywords. Perhaps it has something to do with my Matplotlib version...
Same happened with me
yes, some old version matplotlib will have this problem.
Thank you guy, I had the same problem
The best in you tube .👏
you can just use :
plt.barh(list(reversed(df['language'])),list(reversed(df['popularity'])))
Great videos. I'm so grateful...
Please do a tutorial on numpy as well, it would be super helpful, by the way awesome content😁
Great, amazing video
Great tutorial sir
great instructor
Great video!
Would still love to see a video on counters and DefaultDict!
At 9:30 you correct the numbers of the x-axis with plt.xticks()
Couldn't we just have circumvented that problem by saying
x_indexes = np.array(ages_x)
instead of
x_indexes = np.arange(len(ages_x))
Since that would have given us an array with the original numbers that we could add/subtract the width to/from?
Is there any benefit to the plt.xticks() solution (other than seeing how xticks work)?
I thought the exact same thing, why is he making his life more complicated than necessary? There is no problem with adding/subtracting offsets directly from the ages np.array, it just works. It makes it less hacky, too.
just a suggestion for people with large samples, Use seaborn style, this 538 gets screwed when number of labels is more.
thank you for python tutorial
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
great video.
Thank you so much for your hard work! You are a great teacher and your video tutorial represent a valuable resource :)
For the side by side bar plots, I found that using the plt.bar() args align='edge', align='center', and align='edge', along with width=-0.75, 0.5, 0.75 is easier than using numpy and specifying the tick labels.
Another great tutorial. Thank you. However, using a Jupyter Notebook, I am having a problem with plt.bar, plt.barh. The error I receive is "unsupported operand type(s) for -: 'str' and 'float'.
Thanks you and Brilliant
Best of the best!