【问题标题】:how to get seconds out of time column in csv file using pandas?如何使用熊猫在csv文件中获取秒数?
【发布时间】:2015-12-26 06:41:05
【问题描述】:

以开始时间和结束时间作为两列加载到 csv 文件中我想将其中一列除以数字我该怎么做?

【问题讨论】:

标签: python numpy pandas


【解决方案1】:

正如其他人提到的更多信息会有所帮助,您不能真正“start_time”除以一个数字。如果开始时间是一个整数时间戳,那么是的。试试这样的。

import pandas as pd

THE_DIVISOR = 25342
# data is like 
# station_id, start_time, end_time  
# (INT), (epoch timestamp), (epoch timestamp)

df = pd.read_csv('dobis.csv')
print df.head()

# now to divide a column by another number
# use vectorization
df['divided_timed'] = df['start_time'] / THE_DIVISOR

# can do other things too, great thing about python is that
# most of the time you can just try something and 
# usually the logical sounding code just works.

df['extra_time'] = (df['start_time'] * 2340834) + (df['end_time'] / 2340)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-01
    • 1970-01-01
    • 2013-03-23
    • 2019-10-10
    相关资源
    最近更新 更多