![]() ![]() Now taking the same example forward, the Dataframe “Table” does not give me a clear picture of what my rows and columns represent. Let us get to the second part of our objective, renaming the axis in Python. Also, the marks of students have been replaced by 10, the number that we had given in the function fill_value. Here as we can see that English has been included as an index in place of Physics. With fill_value function, the value given in fill_value will be stored in replacement to “NA”Ĭode: Table.reindex(,fill_value=10) This will happen because the system does not has data on marks of students in English subject. For example, if Physics is re-indexed by English then all marks of all students in English will show as NA or Not Available. Then we use function fill_value to replace the values in the old index with the new ones. In the function, we specify the new index that will be replacing the old ones.We take the “Table” which is our Dataframe and then we apple re-index function on it.Now for re-indexing we follow the following steps: Table=pd.DataFrame(Student_Data,columns=,index=) Now to view the Dataframe we print Table.This Dataframe is stored under the variable “Table” Dataframe is accessed through Pandas where “Student_Data” is taken as the data, columns are mentioned as the name of students and subjects are mentioned as the various index.Here data on marks of Arun, Karan and Aman in various subjects are stored in the variable named as “Student_Data”.To know about how a Pandas Dataframe is made please click here. Here fill_value function will be used to insert value to the index English. The reindex() function with replace index Physics to English and it will also replace the data in the Physics record by NA. Now if I want to replace the subject Physics from the index to English then I will use the reindex function. Let us take their marks in three subjects such as Maths, Physics and Chemistry. Here the marks of students in three subjects are taken as the index. Let us make a Dataframe consisting of three students namely, Arun, Karan and Aman. Re-indexing in Pandas Dataframe in Python Now if I want to change my index because of some error made previously then reindex function can be used. I can do this by using index function in Pandas Dataframe, there I can specify the name of my index for different records. Now suppose I want to index my records according to the data that they represent. ![]() In Pandas Dataframe, indexing originally is done in the form of 0,1,2,3 and so on. After forming a Dataframe, naming the columns and giving an index to the records, one might want to re-index the Dataframe. In this blog, we will learn how to re-index and rename a Pandas Dataframe in Python. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |