python获取Excel单元格内前后字符,类似Excel中left和right函数功能
>>> import pandas as pd
>>> df=pd.read_excel(r'D:xxxxxxxx.xlsx')
>>> df
name score
0 zack 98
1 jacky 60
# 获取name列的前三个字母
>>> df['nameF3'] = df.name.str[:3]
>>> df
name score nameF3
0 zack 98 zac
1 jacky 60 jac
# 获取name列的后三个字母
>>> df['nameR3'] = df.name.str[-3:]
>>> df
name score nameR3
0 zack 98 ack
1 jacky 60 cky