- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想获取最近一天的行,按时间升序排列。
我得到的数据框如下:
label uId adId operTime siteId slotId contentId netType
0 0 u147333631 3887 2019-03-30 15:01:55.617 10 30 2137 1
1 0 u146930169 1462 2019-03-31 09:51:15.275 3 32 1373 1
2 0 u139816523 2084 2019-03-27 08:10:41.769 10 30 2336 1
3 0 u106546472 1460 2019-03-31 08:51:41.085 3 32 1371 4
4 0 u106642861 2295 2019-03-27 22:58:03.679 3 32 2567 4
因为我在这个 csv 文件中获得了大约 1 亿行,所以不可能将所有这些加载到我的电脑内存中。
因此,我想在读取此 csv 文件时以时间升序方式获取最近一天的行。
例如,如果最近一天是2019-04-04,则输出如下:
#this not a real data, just for examples.
label uId adId operTime siteId slotId contentId netType
0 0 u147336431 3887 2019-04-04 00:08:42.315 1 54 2427 2
1 0 u146933269 1462 2019-04-04 01:06:16.417 30 36 1343 6
2 0 u139536523 2084 2019-04-04 02:08:58.079 15 23 1536 7
3 0 u106663472 1460 2019-04-04 03:21:13.050 32 45 1352 2
4 0 u121642861 2295 2019-04-04 04:36:08.653 3 33 3267 4
有人可以帮助我吗?
提前致谢。
最佳答案
我假设您无法将整个文件读入内存,并且该文件是随机顺序的。您可以分块读取文件并迭代这些 block 。
# read 50,000 lines of the file at a time
reader = pd.read_csv(
'csv_file.csv',
parse_dates=True,
chunksize=5e5,
header=0
)
recent_day=pd.datetime(2019,4,4)
next_day=recent_day + pd.Timedelta(days=1)
df_list=[]
for chunk in reader:
#check if any rows match the date range
date_rows = chunk.loc[
(chunk['operTime'] >= recent_day]) &\
(chunk['operTime'] < next_day)
]
#append dataframe of matching rows to the list
if date_rows.empty:
pass
else:
df_list.append(date_rows)
final_df = pd.concat(df_list)
final_df = final_df.sort_values('operTime')
关于python - 读取csv文件时如何以时间升序方式获取最近一天的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56344932/
我正在做作业,经过几天的努力,我无法弄清楚为什么在实现归并排序后,我的列表仅包含链接列表中的最后一个对象。它不输出我的整个链表,只输出最后一个对象。如何更改代码以阻止列表在一个对象之后变为 null。
我想对一列进行排序(它是一个带有 Y/N 的标志列)。它应该在每次点击时在升序/降序之间切换。 我的代码不起作用..我是 VBA 新手。请提供任何帮助。 Private Sub CommandButt
我对如何让它正常工作有点困惑。我需要从用户那里获取数字(直到他们输入负数或达到最大大小),并且对于他们添加的每个数字,将其按升序插入到正确的索引中。现在,由于某种原因,即使我定义了常量 10,我的数组
我相当困惑如何创建一个按钮,将打印到 php 文件的表中的数据按升序或降序排序。 "> Order by Week Sort Week 这是我想要实现的一个简单示例,我只是停留在 php
我在使用 C++ 中的 priority_queue 时遇到问题,我有一个优先级队列 vector ,优先级队列包含多个 Person 对象。现在,我希望 priority_queue 根据年龄对 P
我正在使用 Lodash 按列对表中的数据进行排序。当我单击表格列标题中的箭头时,该特定表格列将按升序或降序排序。但是,我希望每一列首先按升序排序,而不管其他列的当前顺序如何。现在,我的函数只根据当前
如果事先知道哪些列可用,则以下代码可以重新排列列,但如果想按降序/升序重新排列列怎么办? StackOverflow 上有一些类似的帖子,但没有一篇可以在事先不知道哪些列可用的情况下这样做。 ty
在 woocommerce 中,我使用以下代码添加了自定义费用: add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_based_on
这可以很好地以最多 1000 个项目的步长对数据进行分页: var q1 = (from book in table.CreateQuery() where book.PartitionKe
您好,我正在使用以下内容对表适配器返回的数据表的结果进行排序 Dim spots = myDataTable.Where(Function(t) t.UserID = 1).OrderByDesce
这可以很好地以最多 1000 个项目的步长对数据进行分页: var q1 = (from book in table.CreateQuery() where book.PartitionKe
我正在尝试获取数据库中最近的 n 个条目的列表,但将它们按升序排序。 显然我可以使用以下方法获取前 n 个条目: SELECT owner_id,message FROM messages WHERE
我尝试使用此方法将数据提取到 mysql 表 $query=$conn->query("SELECT * FROM users ORDER BY id_user ASC"); 这是我的表结构 用户 i
我正在使用 NSFetchedResultsController 在列表中显示对象 Event。 Event 对象具有 startDate 属性和 eventType 属性,它是 CheckIn 类型
我有以下代码/数据: import numpy as np data = np.array([ [12, 1, 0.7, 0], [13, 2, 0.5, 1], [41, 3
所以我是 C++ 的新手,我正在尝试一些初学者练习,这是问题所在:我必须按升序和降序对整数数组进行排序,但每次我尝试按升序排序时,都会出现 0在我的数组中无处替换以前的数组整数。只有当我使用“升序”选
在我的应用程序中,我有一个任务列表(不,它不仅仅是另一个待办事项应用程序),我使用 NSFetchedResultsController 在 UITableView 中显示任务。这是相关的初始化代码:
本人由于项目开发中需要对查询结果list进行排序,这里根据的是每一个对象中的创建时间降序排序。本人讲解不深,只实现目的,如需理解原理还需查阅更深的资料。 1.实现的效果 2.创建排序的对象
ORDER BY _column1, _column2; /* _column1升序,_column2升序 */
我需要插入两个值 num1 = 50和 num2 = 80成一个已按升序排序的数组。我不能使用动态数组或列表。也没有结构或类。这是一个类作业,所以我必须遵循指导方针。教授建议我新建一个数组,newar
我是一名优秀的程序员,十分优秀!