私はpdシリーズを持っています、
s = pd.Series([1, 2, 3, np.nan])
私がする時、
s.map('this is a string {}'.format)
[out]
0 this is a string 1.0
1 this is a string 2.0
2 this is a string 3.0
3 this is a string nan
フォーマットされた文字列を使用して同じ結果を得るにはどうすればよいですか?
s.map(f'this is a string {?}') ?
ラムダ関数を{x}
:で使用します
print (s.map(lambda x: f'this is a string {x}'))
#alternative with different value
#print (s.map(lambda val: f'this is a string {val}'))
0 this is a string 1.0
1 this is a string 2.0
2 this is a string 3.0
3 this is a string nan
dtype: object
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加