Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dictionary from two columns pandas

pd.Series(df.A.values,index=df.B).to_dict()
Comment

create dict from two columns pandas

In [6]: df = pd.DataFrame(randint(0,10,10000).reshape(5000,2),columns=list('AB'))

In [7]: %timeit dict(zip(df.A,df.B))
1000 loops, best of 3: 1.27 ms per loop

In [8]: %timeit pd.Series(df.A.values,index=df.B).to_dict()
1000 loops, best of 3: 987 us per loop
Comment

python how to create dict from dataframe based on 2 columns

In [9]: pd.Series(df.Letter.values,index=df.Position).to_dict()
Out[9]: {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}
Comment

pandas create dataframe from multiple dictionaries

sales = [{'account': 'Jones LLC', 'Jan': 150, 'Feb': 200, 'Mar': 140},
         {'account': 'Alpha Co',  'Jan': 200, 'Feb': 210, 'Mar': 215},
         {'account': 'Blue Inc',  'Jan': 50,  'Feb': 90,  'Mar': 95 }]
df = pd.DataFrame(sales)
Comment

PREVIOUS NEXT
Code Example
Python :: os module 
Python :: remove list from list python 
Python :: trim strings python 
Python :: change folder icon with python 
Python :: how to save brake lines on textarea in django 
Python :: migrations.RunPython 
Python :: dynamic printing 
Python :: how to backspace in python 
Python :: Swap 2 items of a list in python 
Python :: python binary tree search 
Python :: python telegram bot async 
Python :: como poner estado a un bot en discord 
Python :: Sum of all substrings of a number 
Python :: python string is in list 
Python :: py search and get objects from array 
Python :: cpickle python 
Python :: rotate array in python 
Python :: relative frequency histogram python 
Python :: what is chr function on python 
Python :: The options auto_now, auto_now_add, and defa ult are mutually exclusive. Only one of these options may be present. 
Python :: how to sort values in python 
Python :: python code for create diamond shape with integer 
Python :: how to slice few rows in pandas 
Python :: sqlite python select with parameters 
Python :: calculating auc 
Python :: dict comprehensions 
Python :: package in python 
Python :: torch.stack 
Python :: Accessing elements from a Python Nested Dictionary 
Python :: pandas switch column levels 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =