Pandas-Cookbook 时间戳处理方式

yipeiwu_com6年前Python基础


# -*-coding:utf-8-*-

# by kevinelstri
# 2017.2.17

# ---------------------
# Chapter 8 - How to deal with timestamps.ipynb
# ---------------------

import pandas as pd

'''
  8.1 Parsing Unix timestamps
'''
popcon = pd.read_csv('../data/popularity-contest', sep=' ')
# print popcon.head()
popcon.columns = ['atime', 'ctime', 'package-name', 'mru-program', 'tag']
# print popcon[:5]
print popcon['atime'].dtype

popcon['atime'] = popcon['atime'].astype(int)
# print popcon['atime'][:5]
# popcon['ctime'] = popcon['ctime'].astype(int)
popcon['atime'] = pd.to_datetime(popcon['atime'])
# popcon['ctime'] = pd.to_datetime(popcon['ctime'], unit='s')
# print popcon['atime'][:5]

popcon = popcon[popcon['atime'] > '1970-01-01']
nonlibraries = popcon[~popcon['package-name'].str.contains('lib')]
nonlibraries.sort('ctime', ascending=False)[:10]

以上这篇Pandas-Cookbook 时间戳处理方式就是小编分享给大家的全部内容了,希望能给大家一个参考。

相关文章

用python打印菱形的实操方法和代码

python怎么打印菱形?下面给大家带来三种方法: 第一种 rows = int(input('请输入菱形边长:\n')) row = 1 while row <= row...

python装饰器常见使用方法分析

本文实例讲述了python装饰器常见使用方法。分享给大家供大家参考,具体如下: python 的装饰器,可以用来实现,类似spring AOP 类似的功能。一样可以用来记录某个方法执行前...

Python面向对象类的继承实例详解

本文实例讲述了Python面向对象类的继承。分享给大家供大家参考,具体如下: 一、概述 面向对象编程 (OOP) 语言的一个主要功能就是“继承”。继承是指这样一种能力:它可以使用现有类的...

python-pyinstaller、打包后获取路径的实例

python-pyinstaller、打包后获取路径的实例

使用pyinstaller可以把.py文件打包为.exe可执行文件,命令为: pyinstaller hello.py 打包后有两个文件夹,一个是dist,另外一个是build,可执行文...

python学生管理系统开发

本文实例为大家分享了python学生管理系统开发的具体代码,供大家参考,具体内容如下 学生管理系统(基础版) #定义一个函数,显示可以使用的功能列表给用户 def showInfo(...