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

how to create dictionary between two columns in python

1
2
3
4
5
6
7
dict(zip(df.state, df.name))
 
{'AK': 'Alaska',
 'AL': 'Alabama',
 'AR': 'Arkansas',
 'AZ': 'Arizona',
 'CA': 'California'}
Comment

PREVIOUS NEXT
Code Example
Python :: seaborn histplot modify legend 
Python :: pandas read excel with two headers 
Python :: relative path django 
Python :: how to iterate through a list in python 
Python :: python insert sorted list 
Python :: python if any element in string 
Python :: fcm_django 
Python :: what is the difference between tuples and lists in python 
Python :: python hide print output 
Python :: decode multipart/form-data python 
Python :: set column datatype pandas 
Python :: how to use get-pip.py 
Python :: generate dates between two dates python 
Python :: redirect parameters flask 
Python :: pygame tutorial 
Python :: get an item out of a list python 
Python :: queue python 
Python :: suppress python vs try/except pass 
Python :: kivy button on click 
Python :: python start with 
Python :: python count variable and put the count in a column of data frame 
Python :: python submit work to redis 
Python :: get multiple inputs in python 
Python :: turn off warning when import python 
Python :: python3 shebang line 
Python :: Django custome login 
Python :: Python program to implement linear search and take input. 
Python :: save numpy array 
Python :: make the first letter of a string upper case 
Python :: python print value and variable name 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =