 Hello and welcome to this video lecture. In today's video lecture, we shall see how to read data from a file and how to write data or save data to a file using the NumPy library. So this is the learning outcome that after the end of the session you will be able to read from and write data to text files using NumPy library routines. So before we proceed ahead with today's video lecture, I strongly recommend that you go through the NumPy documentation which is available on the official NumPy library as it will help you to get accustomed with the NumPy library. So as you can see on the slide, this slide shows you the routines that are available in NumPy for reading data. NumPy.load.txt is the routine to load data from a text file, generate from text that is GEN from txt. This routine helps you to load data from a text file and it also supports handling missing values. Many a times in data science, the data set has missing values. So in case you want to replace this missing values with some particular number, you can use gen from txt. Some file is another important routine which helps you to read data in a text or a binary file. Now we shall see how to use each of these routines by looking at an example of each one of them. So let us look at an example of the routine load txt. This routine as mentioned earlier loads data from a text file. So I have just used this routine to open the contents of the file test.txt and I have printed the contents of test.txt which has an array in the format that is displayed. So the output that I have is a 3 cross 3 matrix and the output has the number starting from 1 through 9. This is how we use the load txt routine to read data. Next we have the gen from txt. This routine loads data from a text file with missing values handled as specified. So as mentioned earlier we can handle missing values if any in the data set. Now there are different parameters and the descriptions that we can use as parameters with the routine. File name as we know is the file name or the data set that we want to read. The delimiter is the string that is used to separate values. So when there are more than one values in the data set the delimiter that may be a space or that may be a comma or a semicolon is the string or the character that is used to separate the values. The missing values is the set of strings corresponding to missing data. Filling values that is filling underscore values is a set of values to be used as default when the data is missing. Now we shall see the examples of all these parameters in the upcoming slides. Some more parameters that are used in gen from txt use columns that is use It specifies which columns to read with zero being the first column. So if you want to read some specific columns from the data set you can use use columns parameter and max rows that is max underscore rows is the maximum numbers of rows you want to read. So we shall see the examples of gen from txt. This is a single example of how to use the gen from txt routine. I am using the same file that is missing underscore data.txt which has this file. Now this file has six rows as you can see and it also has five columns. But as you can see the fifth row has no values. So when we use gen from txt all the missing values are shown as NaN where NaN stands for not a number. So the missing values are filled by NaN by default. This is the default value for any missing value if there is any missing value in the data set it is replaced by NaN as default value. Now when I use the filling values parameter and I give the value as five everywhere that the data is missing it will be replaced by five. So in the fifth row as we had seen earlier all the column values in the fifth row were NaN and they have been replaced successfully with five. Five being the value of the filling values parameter. This is how you can replace the missing values with a particular value. Now moving ahead you can use the use columns parameter to read specific columns from the data set. Now first parameter one means the first column and minus one means the last column. So as the indices starts from zero, zero, zero column will be the first. The parameter here past one is the second column in fact from the data set and minus one is the last column. So we see that only the data from the two columns as specified is printed when we pass the use columns parameter and the output is generated as shown in the slide. Moving ahead if we want to skip few rows from the starting of the data set or at the end of the data set we can use these parameters as shown skip header will skip the number of rows as mentioned starting from row one whereas skip footer will skip the number of rows as mentioned starting from the last row. Now I want to skip one row from the beginning of the data set and one row from the end of the data set that is the starting row and the ending row. So when I pass skip underscore header equals one and skip underscore footer as one it skips the first row and the second column the first row and the last row and the output that you see is the data from the middle rows except from the first row and the last row. Moving ahead now this is how we use the from file routine from file routine takes these parameters the name of the file count as minus one and separator as the column. Now as mentioned this file is a CSV file and that is why we are using the separator as column count is given the value minus one which specifies that we read all the data from the file once we print the array we get the data as mentioned in the output. So this is how we use the from file routine. Now moving ahead let us see the routines in NumPy for writing and saving data. In this video we shall see two routines one is NumPy.save txt which saves data to a text file the other is NumPy.to file routine which helps us to write array to a file as text. Now we shall look at the examples of both these routines save txt it saves or stores data in a file in a CSV format. Here we are taking an array which is ranging from one to through hundred and we are printing that array and the data we are saving in a CSV format the delimiter is a comma as we know that CSV values are separated by commas and the data that we want to read write is stored in array g so we are passing the array g and the format is the integer format so we are passing %d as the parameter fmt and now this command will store the data in the file array.csv in the CSV format. This is how we usually write data to be stored in a .csv file. Let us see how to use the two file routine again we have the data to be written from one through 100 now we are storing the data in array g and I am calling the two file routine passing the name of the file that is array 1.csv the separator is a comma to separate the comma separated values and the format here is %d specifying the type or the format in which we need to save the data that is integer. This routine writes data to the file specified in CSV format. Now let us pause here for a moment and answer the question. The question is which of the following is not a function to read data in numpy. The answer to the question is get data we have seen that gen from txt load txt and from file these are the routines mentioned in numpy library to read data whereas get data is a function available in C to read data so get data is not a function to read data from numpy library. These are the references you may refer to the official numpy documentation and also to the NPTEL course python for data sign for further explanation and further details. Thank you.