# if the pattern is more complex, replace with regex or longer pattern
dtcols = [c for c in df.columns if str(df.iloc[0, df.columns.get_loc(c)]).endswith('0Z')]
# use to_datetime rather than astype, you have more control over conversion
df.loc[:, dtcols] = pd.to_datetime(df.loc[:, dtcols], errors='coerce')
您可以通过测试行中每列的格式来收集列名。也就是说,如果列值的字符串与某个模式匹配,则将该列添加到列列表中
相关问题 更多 >
编程相关推荐