YTread Logo
YTread Logo

Data Analysis with Python for Excel Users - Full Course

Mar 29, 2024
follow the same logic. So here I'm going to copy the

data

frame that we created for the bar chart, which is this one, DF underlines people underlines 2020. This is what we created before using that index attribute. And that's in the method. So here I'm going to copy this. And now I'm going to show it to you here so you can remember what's inside this

data

frame. And it is here. Here, as you can see, we have the 2020 column. And the countries are in the index. Then everything is fine. That is what we need. That is the format we need to make the pie chart.
data analysis with python for excel users   full course
But there is one small thing we have to modify. And this is the name of the column, because it's now 2020. There's a number in this, I actually think it's an integer. Therefore, it is not good practice to have numbers in columns. So what we need to do is convert this to a string.   And to do that, we use that rename method. So we type that rename, we open parentheses and now we use the columns argument, so we type columns and then we open these braces. And now we write the name of the column that we want to change, which is 2020.
data analysis with python for excel users   full course

More Interesting Facts About,

data analysis with python for excel users full course...

And we are going to convert this integer value into a string. So we open the quotes and write 2020. Apparently they are the same, but the green one is an integer and the red one is a string. Now, to save these changes, I'm going to type in place equals to true. And I'm going to run this. Now that we can make the graph here, I'll write the name of the data frame. And now I'm going to use that plot method.   So here I write that plot. So the first argument is kind, here I write pi. So the current is pi   a.
data analysis with python for excel users   full course
Now I run this here, I forgot to include that argument and. And I'm going to write here.   Then the argument and is supposed to have the data.  So in this case, I'm going to show you the data frame here again. So the data is here in 2020. So we should write here 2020. So I'm going to delete this. And here, in the Y argument, you write the column that has the data. So that's what we did.   So now I run this. And now we finally have our pie chart. So here is the pie chart. This is how you make a pie chart.
data analysis with python for excel users   full course
If you want, you can even add another argument like the title, for example, here. I can say that this is a population in 2020. But in this case in percentages, so write this in our we have this title. This is how to make a pie chart in pandas.   Alright, so far, we have created a pivot table on many charts using Pandas, and in this video, we will learn how to export the pivot table also on the charts that we made with pandas. So let's start by exporting the plots we made with pandas and to do that we first need to import matplotlib.
So we write import Math plot lip, that pie chart, and then we write like PLT. So this PLT represents this matplotlib.pi graph. Now we run and import matplotlib. And now we can use this PLT   to save the graph. So we write PLT dot save fic.  And now we open parentheses here, we have to write the name of the file that we want to export.  And here, I'm going to write my underline test   that png. So this is the extension. And this is the name of the file. And now before we export this file, I'm going to show you something here.
You probably know that when we do the plot with pandas, we get these words here that say access the subplot and all that.   Then we can get rid of these words using the show method. So we will write PLT which is shown in parentheses. And if we run this, we'll export this figure. And let's also get rid of these words. So let's try to run this. And as you can see here, all those words disappeared.   And we also export the figure to a PNG file. And now this file should be located in the same folder where you have this Jupyter Notebook file.
Okay, I'm going to open that file. But first, I'm going to export the pivot table. So I copy this DF underline pivot and paste it here.   To export it, we have to use that Excel method. Alright, underline Excel.   And now I open parentheses here, we write the name of the file where we are going to export this dynamic table. So in this case, I'm going to call it dynamic underline table that XL s x.   This is the Excel extension. And this is the name of this file. Now I run this and now the pivot table will be exported.
Okay, now I'm going to open the Excel file and the PNG file that we created. So it's here, and here we have the chart, we export it and also the pivot table.   As you can see here, the plot looks exactly the same as the one we created here with the pandas.   And the pivot table is the same. So I'm going to show you what the pivot table looks like. And here is the pivot table we exported. I open it in Google Sheets and it looks exactly the same. And that's it for this video to learn how to export data frames and charts.

If you have any copyright issue, please Contact