我有一个类似这样的sql查询:
display = pd.read_sql_query("""
SELECT UserId, ProductId, ProfileName, Time, Score, Text, COUNT(*)
FROM Reviews
GROUP BY UserId
HAVING COUNT(*)>1
""", con)
有人能帮我用熊猫的代码吗?你知道吗
我试过:
cols = ['UserId', 'ProductId', 'ProfileName', 'Time', 'Score', 'Text']
df[cols].groupby('UserId').agg({'UserId':'count'})
这并没有给我从那个查询中得到的输出。你知道吗
这是数据集:
https://www.kaggle.com/snap/amazon-fine-food-reviewsdatabase.sqlite
因为你没有提供任何样本数据
可能的答案是
df[cols].groupby('UserId').count()
通过使用groupby和count,您可以很容易地做到这一点。你知道吗
相关问题 更多 >
编程相关推荐