将时间增量应用于csv列

时间:2017-03-20 19:19:11

标签: python csv pandas

我正在尝试更改给定列中的所有行,以便将其推回9小时(-9小时)

我似乎无法在熊猫身上弄清楚这一点。

import os, sys
import glob
from datetime import datetime, timedelta
import numpy as np
import pandas as pd
from pandas import DataFrame
import csv


dirListing = '/Users/Desktop/timezone_test'
extension = 'csv'
os.chdir(dirListing)

for fname in glob.glob('*.{}'.format(extension)):

    df = pd.read_csv(fname)
    df['Conversion Date'] = pd.to_datetime(df['Conversion Date'])
    for x in df['Conversion Date']:
        x.to_timedelta(hours=-9)

1 个答案:

答案 0 :(得分:1)

从datetime列中减去timedelta:

df = pd.read_csv(fname)
df['Conversion Date'] = pd.to_datetime(df['Conversion Date']) - timedelta(hours=9)