Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dictionary from two columns pandas

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

convert 2 columns to dictionary pandas

dict(zip(df.a,df.b))
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

dict column to be in multiple columns python

In [2]: df = pd.DataFrame({'a':[1,2,3], 'b':[{'c':1}, {'d':3}, {'c':5, 'd':6}]})

In [3]: df
Out[3]:
   a                   b
0  1           {u'c': 1}
1  2           {u'd': 3}
2  3  {u'c': 5, u'd': 6}

In [4]: df['b'].apply(pd.Series)
Out[4]:
     c    d
0  1.0  NaN
1  NaN  3.0
2  5.0  6.0
Comment

PREVIOUS NEXT
Code Example
Python :: sha256 pandas 
Python :: python selenium itemprop 
Python :: converting a string to a dictionary in python 
Python :: how to traverse a linked list in python 
Python :: sort dictionary python 
Python :: ellipsis in python as index 
Python :: absolut beginners projects in python with tutorial 
Python :: how to leave some parameters in python and let the value be anything 
Python :: how to add numbers on top of bar graph in jupyter notebook 
Python :: matplotlib set y lim 
Python :: iterating over 2d array python 
Python :: drop a column in pandas 
Python :: listing index elasticsearch python 
Python :: how to find determinant in numpy 
Python :: python interpreter clear screen 
Python :: how to set screen brightness automatically depending on battery percentage using python 
Python :: python prayer time 
Python :: how to print something in python 
Python :: Keras library for CIFAR-10 dataset 
Python :: how to ask someone for their name in python 
Python :: godot 2d movement 
Python :: How to efficiently find the first index in an array of distinct numbers that is equal to the value at that index? 
Python :: somma in python 
Python :: flask import jsonify 
Python :: pandas read excel 
Python :: how plot graph by using group by function in python 
Python :: how to stop code in ursina 
Python :: print zip object python 
Python :: python cache return value 
Python :: wxpython custom dialog 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =