5
以下のデータフレームがあります。長さがx未満の場合は文字列を置換
a = {'Id': ['ants', 'bees', 'cows', 'snakes', 'horses'], '2nd Attempts': [10, 12, 15, 14, 0],
'3rd Attempts': [10, 10, 9, 11, 10]}
a = pd.DataFrame(a)
print (a)
文字( '-s')を4文字に追加できます。私は以下をうまく試してみました。 ValueError:Seriesの真理値はあいまいです。 a.empty、a.bool()、a.item()、a.any()またはa.all()を使用します。
if a['Id'].str.len() == 3:
a['Id'] = a['Id'].str.replace('s', '-s')
else:
pass