0

I've been trying to put together a working, simple implementation of this but my grip on pandas at this point in time is shaky. So suppose:

df1: Field1 0 a 1 b 2 c 3 a 4 c

series1: a s1 b s2 c s3

series1 contains all the unique values of df1.Field1 in its index. I would like to add a column to df1 which contains the values of series1 mapped according to corresponding value of df1.Field1 found in series1.index. So the result would be:

df1: Field1 Field2 0 a s1 1 b s2 2 c s3 3 a s1 4 c s3

Thankyou for your guidance.

dmbhatti
  • 314
  • 2
  • 11
  • Use `df1['Field2'] = df1['Field1'].map(series1) ` – jezrael Mar 12 '19 at 07:46
  • 1
    Ah....that works. I didn't recall that df1.['Field1'] returns a Series which is x in the pandas.Series.map documentation example: https://pandas.pydata.org/pandas-docs/version/0.23.3/generated/pandas.Series.map.html. Also the post u link as duplicate deals with dicts in particular. Thanks! – dmbhatti Mar 12 '19 at 08:11

0 Answers0