I'm looking to do a row by row dictionary mapping of two columns of a headered multi-column csv read in to a pandas DataFrame
via read_csv()
. In other words, for each row, make the value in column X the key, and the corresponding value in column Y the value.
With many operations in pandas
being element-wise, I surmised that I could possibly achieve this with the following one-liner:
{df['X'] : df['Y']}
Alas, no such luck.
Does pandas
expose its own way of doing this? I'll also be looking to something similar with a .xls and a .xlsx.
Python: 2.7.11
Pandas: 0.18