Python 如何检查数据帧中的所有列是否包含时间戳
我的数据包含这样的时间2015-04-01 12:15:12-07:00,我想循环数据帧列中的所有行以检查-07:00有多少行Python 如何检查数据帧中的所有列是否包含时间戳,python,pandas,datetime,timestamp,Python,Pandas,Datetime,Timestamp,我的数据包含这样的时间2015-04-01 12:15:12-07:00,我想循环数据帧列中的所有行以检查-07:00有多少行 new_list = [] for item in {"local_time", "basic_verification_local_time"}: dropped_data[item] = pd.to_datetime(dropped_data[item]) if dropped_data[item].ast
new_list = []
for item in {"local_time", "basic_verification_local_time"}:
dropped_data[item] = pd.to_datetime(dropped_data[item])
if dropped_data[item].astype(str).str.isdigit('-07:00'):
new_list.append(item)
Output: TypeError: wrapper() takes 1 positional argument but 2 were given
-07:00
是UTC偏移量-您可以解析为datetime并检查偏移量在-7小时的位置。例:
import pandas as pd
# some dummy data...
df = pd.DataFrame({'time': ["2015-04-01 12:15:12-07:00", "2015-04-01 13:15:12-07:00",
"2015-04-01 14:15:12-08:00", "2015-04-01 15:15:12-08:00"]})
# to datetime
df['time'] = pd.to_datetime(df['time'])
# count occurances where UTC offset is -7 hours
print((df['time'].apply(lambda t: t.utcoffset()) == pd.Timedelta(hours=-7)).sum())
# 2
欢迎使用SO,请添加您的数据样本。如果没有完整的reprex,我们将很难解决问题(请参阅)。请为您使用的语言添加标签,以便专家能够找到您的问题。