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

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

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 :: numpy round to int 
Python :: dataframe to list pyspark 
Python :: as type in pandas 
Python :: pandas iterrows 
Python :: after groupby how to add values in two rows to a list 
Python :: Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python 
Python :: python requests response get text 
Python :: web crawler using python 
Python :: sort list by key 
Python :: python sleep 1 second 
Python :: wordle python 
Python :: templateDoesNotExist Django 
Python :: get just filename without extension from the path python 
Python :: python checking if something is equal to NaN 
Python :: python repeting timer 
Python :: python logging basicconfig stdout 
Python :: dictionary with double key python 
Python :: argparse required arguments 
Python :: replace string if it contains a substring pandas 
Python :: django migrate fake zero 
Python :: python regex group 
Python :: program count the number of occurrences of a letter in a string python 
Python :: python to excel 
Python :: repeat array along new axis 
Python :: simple secatter plot 
Python :: pandas select a row 
Python :: Import "whitenoise.django" could not be resolved 
Python :: find character in python 
Python :: python slice dictionary 
Python :: pandas series to tuple list 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =