Python 在dataframe中指定productID时如何返回特定的审阅数据
我正在尝试返回特定productID的审阅数据。我已成功返回多个具有以下语法的列:Python 在dataframe中指定productID时如何返回特定的审阅数据,python,pandas,dataframe,Python,Pandas,Dataframe,我正在尝试返回特定productID的审阅数据。我已成功返回多个具有以下语法的列: #display productID and review text df1 = df[['asin', 'reviewText']] #display all orders with specific ASIN filtered_data = df[df["asin"]== '0739079891'] 我已使用以下语法成功返回给定productID的所有
#display productID and review text
df1 = df[['asin', 'reviewText']]
#display all orders with specific ASIN
filtered_data = df[df["asin"]== '0739079891']
我已使用以下语法成功返回给定productID的所有数据:
#display productID and review text
df1 = df[['asin', 'reviewText']]
#display all orders with specific ASIN
filtered_data = df[df["asin"]== '0739079891']
是否可以使用=指定给定的asin(productID)并同时显示与该特定productID关联的reviewText?用于按掩码和列表中的列名进行筛选:
filtered_data = df.loc[df["asin"]== '0739079891', ['asin', 'reviewText']]
除了上面的答案,我还经常使用df.query。语法:
dfSub = df.query('asin=="0739079891"')[['asin', 'reviewText']]
谢谢你的回复!这正是我要找的!