remove default index from pandas dataframe

Solutions on MaxInterview for remove default index from pandas dataframe by the best coders in the world

showing results for - "remove default index from pandas dataframe"
Fallon
15 Feb 2019
1 pythonCopyimport pandas as pd
2
3my_df = pd.DataFrame({
4    'Person': ['Alice', 'Steven', 'Neesham', 'Chris', 'Alice'],
5    'City': ['Berlin', 'Montreal', 'Toronto', 'Rome', 'Munich'],
6    'Mother Tongue': ['German', 'French', 'English', 'Italian', 'German'],
7    'Age':  [37, 20, 38, 23, 35],
8
9},index=["A","B","C","D","E"])
10
11df_reset=my_df.set_index('Person')
12
13print("Initial DataFrame:")
14print(my_df,"\n")
15
16print("After setting Person column as Index:")
17print(df_reset)
18
Sara
07 Jan 2017
1 pythonCopyInitial DataFrame:
2    Person      City Mother Tongue  Age
3A    Alice    Berlin         German   37
4B   Steven  Montreal         French   20
5C  Neesham   Toronto        English   38
6D    Chris      Rome        Italian   23
7E    Alice    Munich         German   35
8
9After setting Person column as Index:
10             City Mother Tongue  Age
11Person
12Alice      Berlin         German   37
13Steven   Montreal         French   20
14Neesham   Toronto        English   38
15Chris        Rome        Italian   23
16Alice      Munich         German   35
17