Convert pandas DataFrame to Dictionary in Python (Example) | Create dict Object | to_dict() Function

Convert pandas DataFrame to Dictionary in Python (Example) | Create dict Object | to_dict() Function

How to create a dictionary from a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/convert-p... Python code of this video: import pandas as pd # Import pandas data = pd.DataFrame({'x1': [4], # Create pandas DataFrame 'x2': [3], 'x3': [2], 'x4': [1]}) print(data) # Print pandas DataFrame my_dict = data.to_dict() # Convert pandas DataFrame to dict print(my_dict) # Print dictionary {'x1': {0: 4}, 'x2': {0: 3}, 'x3': {0: 2}, 'x4': {0: 1}} Follow me on Social Media: Facebook – Statistics Globe Page:   / statisticsglobecom   Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe   Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython   LinkedIn – Statistics Globe Page:   / statisticsglobe   LinkedIn – R Programming Group for Discussions & Questions:   / 12555223   LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534   Twitter:   / joachimschork   Music by bensound.com