我有一个数据框(新),看起来像这样:
num name1 name2
11 A AB
14 Y YX
25 L LS
39 Z ZT
....
我只想提取打印语句中的数值,这样我就有一个如下所示的输出:
The value is 11
The value is 14
The value is 25
...
我不确定执行此操作的正确格式是什么,因为以下代码只是迭代“值是”。
for index, row in new.iterrows():
print('The value is').format(new['num'])
Use str.join
和 f 弦
print('\n'.join(f'The value is {n}' for n in new.num))
The value is 11
The value is 14
The value is 25
The value is 39
一个轻微的变体和更多内容来展示如何使用print
功能...
print(*(f'The value is {n}' for n in new.num), sep='\n')
The value is 11
The value is 14
The value is 25
The value is 39
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)