如何删除列表中的数字?

时间:2019-06-20 22:53:52

标签: python-3.x list arraylist

我有一个数据框,其中一列是列表列表。我想删除该listoflist列中的数字。我该怎么办?

mylist = [['302','is','my','apartment','number'],['I','wake','up','at','7','am'],['I','spent','10','dollars','for','lunch']]

[word for word in mylist if word.isalpha()]

我尝试了上面的代码,但返回“ AttributeError:'list'对象没有属性'isalpha'”

我的预期结果:

[['is','my','apartment','number'],['I','wake','up','at','am'],['I','spent','dollars','for','lunch']]

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

您想将您写的内容应用于my list中的每个列表。

答案 1 :(得分:0)

您必须编写一个嵌套的理解列表:

mylist = [['302','is','my','apartment','number'],['I','wake','up','at','7','am'],['I','spent','10','dollars','for','lunch']]

print([[word for word in arr if word.isalpha()] for arr in mylist])

输出

[['is', 'my', 'apartment', 'number'],
 ['I', 'wake', 'up', 'at', 'am'],
 ['I', 'spent', 'dollars', 'for', 'lunch']]