如何删除“配方开始”或“配方结束”列包含字母/符号的行?公司名称:
Title Recipe Start Recipe End Year
0 cookie 500 400 2013
1 soup 600 650 1993
2 rice 30 5A-EE 1810
3 ramen v vii 2001
4 pate EP56 2KP 2005
输出:
^{pr2}$我所做的:
import pandas as pd
import re
raw = {'Title': ['cookie', 'soup', 'rice', 'ramen', 'pate'],
'Recipe Start': [500, 600, 30, 'v', 'EP56'],
'Recipe End': [400, 650, '5A-EE', 'vii', '2KP'],
'Year': [2013, 1993, 1810, 2001, 2005]}
data = pd.DataFrame(raw, columns = ['Title', 'Recipe Start', 'Recipe End', 'Year'])
data['Recipe Start'] = data[[(re.search(r'[a-zA-Z]', x)==False) for x in data['Recipe Start'].astype(str)]]
print(data)
选项1}的过滤
^基于{
选项2
^{pr2}$str.isdigit
如果这些是对象列,则需要事先转换为
str
,然后可以对这些列使用str
访问器方法:选项3
applymap
+str.isdigit
{cda>你可以用这个来代替
相关问题 更多 >
编程相关推荐