Welcome.
So once again we have these three for this year and each of them has a column with some data values
and a header called value and Olmo write a program that will access these three files read their data
in Python and calculate three average values one for each of the three columns.
These can be probably done in different ways using different libraries but one easy way to do this is
to use the Panas library.
So the panderers library is a data analysis library and.
It's like an interface that creates a data or frame object inside Python data or frame object like structure
that hold the data.
So you've got to think of it as yet another platform data type.
So as you work with other libraries you will discover other complex later types.
So first I'll go ahead and calculate the average value all the values inside the file 1.60.
First of all how import are the panels library and what we want to do first is generate a data free
object out of the first textfile.
So we will read the data of the first text file.
We will store those data in a data frame object and we want to store the object in a variable.
So remember variables are like containers where we can store everything and I'll call my variable div
then I'll generate the data frame using the Pandurs I read C the method.
So read 60 cents for read characters separated values and our text file is such a file.
So it has that data structure.
The file could also be seen for all but C as if all things work the same.
So Pandurs that is the event we need to pass a parameter to the Richard's method.
That parameter is the file path where we want to convert to a data frame so we want to convert that
file and I'll pass my path here which is the analysis of the name of the file.
I notice here that the path is a string Nader type.
So Python recognizes stream's objects when you pass the string to the Red Sea is your method.
Let's use the method parses the string so it sends String objects and locate the file in the computer
through the given string.
So let's end the year and we have a or frame object generated to display the data frame.
If you want by just calling the variable that holds the data frame so this is the data frame.
So this is constructed for either which in this case is valid value string and the data frame also has
an index column which was assigned some default values as you see here.
And of course the data frame also has those values.
So to calculate the mean value of all the different values we just go ahead and apply the mean method
to the data from object.
So they have the dot method.
This is a mean value.
So it was quite easy.
No we can calculate the average values of the other files the same way.
So we can repeat the same actions but here we have 3 4 Songlian we can do that both.
Imagine if we had the waltz on lots of files and in such case we would need to use a for loop.
That's exactly what I'll do now.
But in order to iterate through all the file paths I first need to have all these so file path strings
in a smart way to get at least easy to use glop to my library.
So first you should go ahead and install the library in your command line using p.
Installed with all up to good once the library has been installed.
You don't have to start anything.
Just go ahead and import the library in your console when you want to use a method over a library that
generates a list of four file paths that math is called globe and I want to store the list of the file
path strings inside a variable of course.
So let's say for all this equals and go to the ultimate lump.
So a global math of the OP to luxury and here we need to pass is a full path for where the files are
located.
So that is C..
Now this is and here we can play around by using an asterisk and a dot DXi after that.
That means we want all the files containing dot DXi exception those that execute and see what you got
in the file is variable.
So it certainly solve all the TXU file paths.
Now we have a list of 5 paths and we can iterate through.
At least I know exactly the same action for all the items of a list.
Let's say for file in file we create a data frame object and call the methods of the Penates library
then pass the file path to that object.
So that would be the file variable.
Think of the file the variable as temporary variables so they all have different values or each iteration.
Next we can calculate the mean value of the current data frame for the duration our then we print all
the value on the screen.
That's it.
Executer and we get three values here.
So each of the values represents the average value for each text while these values are actually domestic
panderers data type calls serious.
So if you like to actually return a plain floor Python data type you could apply the full function to
these numbers.
So let's do just that.
Let's modify our code and just press the upper arrow key to recall the previously executed statement.
What you want to do is add a line that converts the series data to a folded up type we can use the full
function for that.
So as soon as a variable is created we will grab that value of that variable and pass it to the full
function which we converted to four data.
That's it.
Exec cute.
And here we have three main values.
So I hope this is fun and full of useful information for you.
Please feel free to post this question if there is anything you need to talk about and see you in the
next lecture.