可以使用Pandas的查询(query)和筛选特定列(loc)函数来实现将特定列打印到符合条件的行上。以下是示例代码:
import pandas as pd
df = pd.read_csv('example.csv')
# 打印 customer_name, product_name, amount三列,对amount大于100的行筛选并打印
result = df.loc[df['amount'] > 100, ['customer_name', 'product_name', 'amount']]
print(result)
以上代码可以简化为一行代码的形式:
result = df.query('amount > 100')[['customer_name', 'product_name', 'amount']]
print(result)