pandas中截取一列字符串中每行字符串的一部分
1 import pandas as pd 2 df = pd.DataFrame([['12345',1], 3 ['23456',2], 4 ['34567',3], 5 ['45678',4], 6 ['56789',5], 7 ['67890',6]],columns=['str','num']) 8 print(df)
输出结果如下图:
如果想要截取中间三位字符,
df['str'].str[1:4]
https://www.cnblogs.com/zhangzhixing/