6

Pandas: Transforming two DataFrame columns into a dictionary

 1 year ago
source link: https://proinsias.github.io/til/pandas-transforming-two-dataframe-columns-into-a-dictionary/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Francis T. O'Donovan

Data Science Manager at LeanTaaS – Planet discoverer, researcher, developer, geek.

Pandas: Transforming two DataFrame columns into a dictionary

May 3, 2023

less than 1 minute read

import pandas as pd

df = pd.DataFrame(dict(a=["a","b","c"],b=[1,2,3]))

df_dictionary = dict(zip(df["a"],df["b"]))
df_dictionary

# Output is {'a': 1, 'b': 2, 'c': 3}

Via Lucas Soares.

Tags: pandas python til

Categories: til

Updated: May 3, 2023

Previous Next

You may also enjoy

Pandas: Display DataFrames side by side

May 3, 2023

less than 1 minute read

from IPython.display import display_html from itertools import chain,cycle def display_side_by_side(*args,titles=cycle([''])): # source: https://stackove...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK