首页 > 解决方案 > 将整列中的时间转换为字符串

问题描述

我想将整个列中的时间更改为字符串。请举例说明方法。下面给出的是我的数据。

timeseries  CCN Number Conc SS
0   00:00:00    15.810967   0.1
1   00:05:00    358.401000  0.3
2   00:10:00    797.538333  0.5

下面给出的是我的代码:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
load_file=pd.read_excel(r'E:\CCNC\CCNCCodes\Modulated output\Copy of Final_modulated_ccnc_data.xlsx',header=0)
load_file.columns
s=load_file.loc[0:289,['Timeseries',' CCN Number Conc','SS']]

谢谢你。

标签: pythonpandasstringdataframedata-science

解决方案


只需告诉 Pandas 将您想要的列加载为字符串:

pd.read_excel(filename, dtype={'Timeseries': str}, header=0)

这样您就不必在以后转换它们,这会浪费时间。


推荐阅读