在一个csv文件中加载了开始时间和结束时间作为两列,我想用一个数字划分其中一列,我该怎么做?
答案 0 :(得分:0)
正如其他人提到的更多信息会有所帮助,你无法真正划分 a' 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)