Pandas: Transforming two DataFrame columns into a dictionary
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.
Categories: til
Updated: May 3, 2023
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...
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK