【发布时间】:2021-11-15 03:36:56
【问题描述】:
关于如何查看某个单词是否在 pandas 列中的任何提示?
# initialise data of lists.
data = {'Colour':['Blue andtext', 'Greys', 'Potato', 'Yellow','Tree'],
'Values':[20, 21, 19, 18,44]}
df2 = pd.DataFrame(data)
假设:
colours = ['Blue','Grey','Yellow']
如何检查 df2['Colour'] 是否实际上是一种颜色并在新列中表示它?
输出应该是
Colour Value Actualcolour
Blue andtext 20 Blue
Greys 21 Grey
Potato 19 NaN
Yellow 18 Yellow
Tree 44 Nan
【问题讨论】:
标签: python-3.x pandas dataframe loops