Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import pandas as pd
- def getFullPath(x):
- ret = ""
- for i in range(1,151):
- ret += getPath(x['cola' + str(i)], x['colb' + str(i)], x['colc' + str(i)])
- return ret
- def getPath(a,b,c):
- if b == 'ret1':
- return 'A'
- elif b == 'ret2':
- if c.startswith('B_'):
- return 'B'
- elif c.startswith('C_'):
- return 'C'
- elif c.startswith('A_'):
- if a.startswith('D_'):
- return 'D'
- else:
- return 'E'
- else:
- return 'F'
- series = {
- 'cola1': pd.Series(['D_1','C_1','E_1'],index=[1,2,3]),
- 'colb1': pd.Series(['ret1','ret1','ret2'],index=[1,2,3]),
- 'colc1': pd.Series(['B_1','C_2','B_3'],index=[1,2,3]),
- 'cola2': pd.Series(['D_1','C_1','E_1'],index=[1,2,3]),
- 'colb2': pd.Series(['ret3','ret1','ret2'],index=[1,2,3]),
- 'colc2': pd.Series(['B_2','A_1','A_3'],index=[1,2,3]),
- 'cola3': pd.Series(['D_1','C_1','E_1'],index=[1,2,3]),
- 'colb3': pd.Series(['ret2','ret2','ret1'],index=[1,2,3]),
- 'colc3': pd.Series(['A_1','B_2','C_3'],index=[1,2,3]),
- }
- df = pd.DataFrame(series, index=[1,2,3], columns=['cola1','colb1','colc1','cola2','colb2','colc2','cola3','colb3','colc3'])
- df['Path'] = df.apply(lambda x: getFullPath(x), axis=1)
- print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement