Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create pandas dataframe from dictionary orient index

pd.DataFrame.from_dict(data, orient='index',
...                        columns=['A', 'B', 'C', 'D'])
       A  B  C  D
row_1  3  2  1  0
row_2  a  b  c  d
Comment

dataframe to dict without index

df.to_dict('index')
Comment

dataframe to dictionary using index as key

#Use the Dataframe index as the key of the dictionary
df.to_dict('index')
Comment

dataframe to dict without index

df.to_dict('list')
Comment

create pandas dataframe from dictionary orient index

data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']}
>>> pd.DataFrame.from_dict(data, orient='index')
       0  1  2  3
row_1  3  2  1  0
row_2  a  b  c  d
Comment

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
Comment

dataframe to dict without index

{0: {'Name': 'John', 'Age': 38, 'City': 'Boston'},
 1: {'Name': 'Sara', 'Age': 47, 'City': 'Charlotte'},
 2: {'Name': 'Peter', 'Age': 63, 'City': 'London'},
 3: {'Name': 'Cecilia', 'Age': 28, 'City': 'Memphis'}}
Comment

dataframe to dict without index

{'Name': ['John', 'Sara', 'John', 'Sara'],
 'Sem': ['Sem1', 'Sem1', 'Sem2', 'Sem2'],
 'Subject': ['Mathematics', 'Biology', 'Biology', 'Mathematics'],
 'Grade': ['A', 'B', 'A+', 'B++']}
Comment

PREVIOUS NEXT
Code Example
Python :: python b string 
Python :: how to unlist a list in python 
Python :: calculate days between two dates using python 
Python :: loop indexing 
Python :: python raise typeerror 
Python :: python read binary trj file 
Python :: python argparse custom categories 
Python :: make button bigger tkinter with grid 
Python :: flatten tf keras 
Python :: django only certain columns from database 
Python :: python string format 
Python :: python edit string variable 
Python :: howe to print all values and keysin d 
Python :: create series in pandas 
Python :: euclidean algorithm recursive python 
Python :: strftime python multiple formats 
Python :: kubernetes python client 
Python :: seaborn pairplot python 
Python :: python pandas read csv from txt tab delimiter 
Python :: pandas get group 
Python :: how to slice a string in python 
Python :: how to add a value to a list in python 
Python :: move file python os 
Python :: how to check dimension of array in python 
Python :: upload to test pypi 
Python :: generate random integers in a range python 
Python :: How to check if a given string is a palindrome, in Python? 
Python :: python check samplerate of mp3 
Python :: read multiple images cv2 
Python :: Python check if all elements exist in another list 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =