Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert a dictionary into dataframe python

import pandas as pd
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index').T
Comment

convert dict to dataframe

#Lazy way to convert json dict to df

pd.DataFrame.from_dict(data, orient='index').T
Comment

convert pandas dataframe/ table to python dictionary

df.to_dict(orient='index')
Comment

dataframe to dictionary

>>> df.to_dict('records')
[{'col1': 1, 'col2': 0.5}, {'col1': 2, 'col2': 0.75}]
Comment

convert a dictionary to Pandas DataFrame

import pandas as pd

my_dict = {key:value,key:value,key:value,...}
df = pd.DataFrame(list(my_dict.items()),columns = ['column1','column2'])
Comment

convert pandas dataframe to dict with a column as key

df.set_index('columnName').T.to_dict()
Comment

PREVIOUS NEXT
Code Example
Python :: stack data horizontally pandas 
Python :: figsize param in pandas plot 
Python :: find the sum of all the multiples of 3 or 5 below 1000 python 
Python :: sqlite3 delete row python 
Python :: flask return error response 
Python :: add time to datetime python 
Python :: linking custom CSS in flask 
Python :: python iterate backwards through list 
Python :: what should you call a decimal value in python 
Python :: pandas drop duplicates from column 
Python :: python glob all files in directory recursively 
Python :: django logout user 
Python :: how to get current date and time in python 
Python :: replace all nan values in dataframe 
Python :: python Program to check if a given year is leap year 
Python :: sklearn cross_val_score scoring metric 
Python :: python get first n elements of dict 
Python :: get sum in range 
Python :: python get item from queue 
Python :: how to add mouse button in pygame 
Python :: create new list in for loop python 
Python :: The Python path in your debug configuration is invalid. 
Python :: best pyqt5 book 
Python :: python os abspath 
Python :: create dict from two columns pandas 
Python :: pandas count the number of unique values in a column 
Python :: import spacy nlp = spacy.load("ar_core_web_sm") 
Python :: python check if class has function 
Python :: # time delay in python script 
Python :: random string generate python of 2.7 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =