I have started learning pandas and got stumbled at the below problem:
Following is a table which has data like:
Book:
B_IDX B_NAME B_AUTHOR B_PRICE B_UTYPE B_ID
1 ABC aaa 12.21 SCI 182
2 BCD bbb 98 ECN 920
3 CDE ccc 22.34 SCI 228
4 DEF ddd 44.11 LIT 761
5 EFG eee 0.99 MAT 10242
6 FGH fff 4.99 MAT 77721
UCODE:
U_ID U_CD
182 9982825
950 9992822
228 9999983
776 9912876
332 9003931
The requirement is to use the if..else logic to pull the data from the above mentioned tables.
Req.:
if B_UTYPE == 'SCI':
pull the record from 'UCODE'
elif B_UTYPE == 'MAT':
split the B_ID in 4 and 1 digits i.e. B_UTYPE.split[:2] and B_UTYPE.split[3:5]
else:
keep the data as it is.
Excepted O/P:
B_ID B_NAME B_AUTHOR B_PRICE B_UTYPE B_ID U_ID U_CD N_COL1 N_COL2
1 ABC aaa 12.21 SCI 182 182 9982825 NA NA
2 BCD bbb 98 ECN 920 NA NA NA NA
3 CDE ccc 22.34 SCI 228 228 9999983 NA NA
4 DEF ddd 44.11 LIT 761 NA NA NA NA
5 EFG eee 0.99 MAT 10242 NA NA 102 42
6 FGH fff 4.99 MAT 77721 NA NA 777 21
Any help/tutorial where I can get some insight to achieve the expected output by meeting the above conditions?
Bookdataframe? Is that intended?