truncate()函数

1 truncate()方法用于截断文件,如果指定了可选参数 size,则表示截断文件为 size 个字符,截断之后 size 后面的所有字符被删除。

参考: https://www.runoob.com/python/file-truncate.html

2 可以筛选时间

1 import pandas as pd
2 import datetime
3 df = pd.read_csv('./data.csv')
4 
5 df['report_date'] = pd.to_datetime(df['report_date'])
6 df = df.set_index('report_date')
7 print(df.truncate( after= '2013/07/09'))

先要将日期用to_datetime转化,再将日期列设置为索引,注意truncate是将日期after之后的删除了

输出:

 1 report_date             aaa     
 2 2013-07-01            5525022
 3 2013-07-02            2554548
 4 2013-07-03            5953867
 5 2013-07-04            6410729
 6 2013-07-05            2763587
 7 2013-07-06            1616635
 8 2013-07-07            3982735
 9 2013-07-08            8347729
10 2013-07-09            3473059

参考: https://www.jianshu.com/p/b91e3ae940ec

原文地址:https://www.cnblogs.com/xxswkl/p/10848274.html