赞
踩
需要把数字类型转化为字符串类型,再进行连接
- df1 = pd.DataFrame({'Year': ['2014', '2015'], 'quarter': ['q1', 'q2']})
- df1['period'] = df[['Year', 'quarter']].apply(lambda x: ''.join(x), axis=1)
- df1
- Year quarter period
- 0 2014 q1 2014q1
- 1 2015 q2 2015q2
- df2 = pd.DataFrame({'Year': ['2014', '2015'], 'quarter': ['q1', 'q2']})
- df2["period"] = df["Year"].map(str) + df["quarter"]
- df2
- Year quarter period
- 0 2014 q1 2014q1
- 1 2015 q2 2015q2
-
- df3 = pd.DataFrame({'Year': ['2014', '2015'], 'quarter': ['q1', 'q2']})
- df3['period'] = df["Year"].str.cat(df["quarter"],sep='|')
- df
-
- Year quarter period
- 0 2014 q1 2014q1
- 1 2015 q2 2015q2
- psi['as_id'] = psi['as_id'].map(lambda x :str(x))
- psi['cat'] = psi['symbol'].str.cat(psi['as_id'],sep='|')
- psi['cc'] = psi['symbol'] + psi['as_id']
- psi['cc']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。