pradeepsf729 / pandas_101

Pandas questions with solutions
1 stars 0 forks source link

reset_index #22

Closed sandeepny441 closed 11 months ago

sandeepny441 commented 1 year ago

import pandas as pd

Sample DataFrame for pet stores in the US

data = { 'Store_ID': [1001, 1002, 1003, 1004, 1005], 'Store_Name': ['Pet Paradise', 'Animal Kingdom', 'Furry Friends', 'Pet Pals', 'Fauna House'], 'Location': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix'], 'Speciality': ['Fish', 'Birds', 'Dogs', 'Cats', 'Reptiles'], 'Rating': [4.5, 4.2, 3.9, 4.7, 4.0] }

df_pet_stores = pd.DataFrame(data)

reset_index_questions

  1. How would you reset the index of the DataFrame without keeping the old index as a new column?
  2. By default, what name is given to the column that holds the old index values when using reset_index?
  3. If you set a new index for the DataFrame using the set_index method, how would you revert back to the original indexing using reset_index?
  4. How can you reset the index of the DataFrame and simultaneously set the drop parameter to True?
  5. If you wanted the new index to start from a number other than 0, how would you achieve this after using the reset_index method?