Pandas: Transforming two DataFrame columns into a dictionary
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.
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.
Leave a comment