dictionary to dataframe index code example
Example 1: dataframe to dictionary using index as key
#Use the Dataframe index as the key of the dictionary
df.to_dict('index')
Example 2: create a dictionary from index and column pandas
import pandas as pd
df = pd.DataFrame({'Name': ['John', 'Sara','Peter','Cecilia'],
'Age': [38, 47,63,28],
'City':['Boston', 'Charlotte','London','Memphis']})
df