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 :: how to sort values of pandas dataframe for iqr 
Python :: python get last element of iterator 
Python :: pip install for python 2 and python3 
Python :: assert keyword python 
Python :: in pandas how to start an index from a specific number 
Python :: how to do a square root in python 
Python :: # invert a dictionary 
Python :: plt.legend( 
Python :: grid search cv 
Python :: short form of if statement in python 
Python :: python numpy vstack 
Python :: time addition in python 
Python :: elif in django template 
Python :: program for factorial of a number in python 
Python :: rotate 90 degrees clockwise counter python 
Python :: Create list with numbers between 2 values 
Python :: heroku python version 
Python :: pandas merge on index column 
Python :: matplotlib overlapping labels 
Python :: display values on top of seaborn bar plot 
Python :: json url to dataframe python 
Python :: if else python 
Python :: python iterate through files 
Python :: use a dictionary to make a column of values 
Python :: python nested list comprehension 
Python :: get only every 2 rows pandas 
Python :: django reverse queryset 
Python :: plt .show 
Python :: how to make a latency command in discord py 
Python :: list to dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =