如何在特定条件下提取大 pandas 中的某些? (情感分析) [英] How to extract certain under specific condition in pandas? (Sentimental analysis)

查看:121
本文介绍了如何在特定条件下提取大 pandas 中的某些? (情感分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片就是我的数据框的样子.我有用户名,电影名和时间列.我只想提取某些电影第一天的行.例如,如果电影a在时间列中的第一个日期是2018-06-27,我希望该日期中的所有行,并且如果电影b在时间列中的第一个日期是2018-06-12,则我只希望那些行.我要如何处理大熊猫?

The picture is what my dataframe looks like. I have user_name, movie_name and time column. I want to extract only rows that are first day of certain movie. For example, if movie a's first date in the time column is 2018-06-27, i want all the rows in that date and if movie b's first date in the time column is 2018-06-12, i only want those rows. How would i do that with pandas?

推荐答案

我假定 time 列为 datetime 类型.如果没有,将其转换 列调用 pd.to_datetime .

I assume that time column is of datetime type. If not, convert this column calling pd.to_datetime.

然后运行:

df.groupby('movie_name').apply(lambda grp:
    grp[grp.time.dt.date == grp.time.min().date()])

Groupby 将源DataFrame分组为与特定电影有关的摸索.

Groupby groups the source DataFrame into grops concerning particular films.

然后 grp.time.min().date()从 当前组.

最后,整个lamda函数仅返回该日期之后的行 (也来自当前组).

And finally the whole lamda function returns only rows from this date (also from the current group).

其他行(电影)组相同.

The same for other groups of rows (films).

这篇关于如何在特定条件下提取大 pandas 中的某些? (情感分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆