[英]Print string list vertically
我有一个数据框如下。
df = pd.DataFrame({'Title': ['x','y','z','aa'], 'Result': [2, 5, 11, 16]})
我只想返回一个包含大于10的文本字符串。
我想要的结果示例如下
From the results in df, the below returned greater than 10:
z
aa
我尝试了下面的方法,但是没有给出我想要的输出。 它在同一行中给出了一个数组。 不像上面。
df2 = df[df['Result']>= 10]
df3 = df2['Title'].values
print ('From the results in df, the below returned greater than 10:\n\t%s' (df3))
更改
print ('From the results in df, the below returned greater than 10:\n\t%s' (df3))
至
print ('From the results in df, the below returned greater than 10:')
for n in df3:
print('\t' + str(n))
与@membraneporential略有不同。
print ('From the results in df, the below returned greater than 10:\n\t', '\n\t'.join(df3))
您有正确的想法,只需将值与常规python结合在一起即可:
long_values = df.loc[df['Result'] >= 10, 'Title']
print('From the results in df, the below returned greater than 10:')
print('\n'.join('\t' + s for s in long_values))
出:
From the results in df, the below returned greater than 10:
z
aa
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.