带有 "wildcard" 的条件语句

Conditional Statement with a "wildcard"

在 table A 中,有第 1 列和第 2 列。

有人知道我可以如何使用左手吗?

我试过了,但我的错误是 left is not defined。

 TableA.loc[TableA['col1'] == left('A',1), 'hasAnA'] = 'Yes'

您可以使用pd.Series.str.startswith()方法:

>>> frame = pd.DataFrame({'colA': ['A12342', 'B123123231'], 'colB': False})
>>> condition = frame['colA'].str.startswith('A')
>>> frame.loc[condition, 'colB'] = 'Yes'
>>> frame
         colA  colB
0      A12342   Yes
1  B123123231  False