-2

I have a dataset like below

category_data

    userid       Frequency  Category    SubCategory
0   axisbankltdi    13705   BFSI        Banking
1   nokiasiemens34  8642    Telecom     EnterpriseTelecom
2   videocond2h     4699    Utilities   DTH
3   pnb             3201    BFSI        Banking
4   nokiasiemens7   2536    Telecom     EnterpriseTelecom
5   one97paytm      2318    BFSI        Payments

figureout_data

    userid       Frequency  Category    tonumber      fromnumber
0   axisbankltdi    13705               9156283564    56454
1   nokiasiemens34  8642                9985986589    54545
2   videocond2h     4699                32354654665   36259
3   pnb             3201                5465546646    414845
4   nokiasiemens7   2536                54354615454   551456
5   one97paytm      2318                45456465146   465466
6   nokiasiemens34  8642                9985986589    54545
7   videocond2h     4699                32354654665   36259
8   pnb             3201                5465546646    414845
9   nokiasiemens7   2536                54354615454   551456  

expected output:

    userid       Frequency  Category    tonumber      fromnumber
0   axisbankltdi    13705    BFSI       9156283564    56454
1   nokiasiemens34  8642     Telecom    9985986589    54545
2   videocond2h     4699     Utilities  32354654665   36259
3   pnb             3201     BFSI       5465546646    414845
4   nokiasiemens7   2536     Telecom    54354615454   551456
5   one97paytm      2318     BFSI       45456465146   465466
6   nokiasiemens34  8642     Telecom    9985986589    54545
7   videocond2h     4699     Utilities  32354654665   36259
8   pnb             3201     BFSI       5465546646    414845
9   nokiasiemens7   2536     Telecom       54354615454   551456  

So i need to fill the variable called Categories by looking at category_data. please help me on this

surendra
  • 31
  • 1
  • 3
  • 5
  • Is this pandas? If so see related: http://stackoverflow.com/questions/25493625/vlookup-in-pandas-using-join – EdChum May 05 '15 at 10:57
  • @brunodesthuilliers I am very new to python, so i don't know much about vlookup in python. So please hep me how to write the code for the above in python – surendra May 05 '15 at 11:04
  • @EdChum , that doesn't look comfortable for me , So please help me in this way – surendra May 05 '15 at 11:07
  • You've not answered my question, is this pandas? Also SO is not a code writing service – EdChum May 05 '15 at 11:08

2 Answers2

0

You want a join (called a merge in pandas) it is sort of the database equivalent of a vlookup. That is how I was taught it originally.

Second Edcum's link. I think that's all you need.

Yupsiree
  • 163
  • 1
  • 8
0

create a dictionary with userid, category as key, value

user_category = dict(zip(category_data['userid'], category_data['Category']))

Map your required column with this dict

figureout_data['Category'] = figureout_data['userid'].map(user_category)
S.Sreeram
  • 225
  • 1
  • 8