我正在尝试更改给定列中的所有行,以便将其推回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)
答案 0 :(得分:1)
从datetime列中减去timedelta:
df = pd.read_csv(fname)
df['Conversion Date'] = pd.to_datetime(df['Conversion Date']) - timedelta(hours=9)