当前位置:首页 » python教程 » 正文

Pandas-Cookbook 时间戳处理方式

看: 920次  时间:2021-01-21  分类 : 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博客。

标签:pandas  

<< 上一篇 下一篇 >>

搜索

推荐资源

  Powered By python教程网   鲁ICP备18013710号
python博客 - 小白学python最友好的网站!