我有问题将一列的 dtype 进行转换。我正在从雅虎财经加载一个 csv 文件。
dt = pd.read_csv('data/Tesla.csv')
这个给我以下信息:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 923 entries, 0 to 922
Data columns (total 7 columns):
Date 923 non-null object
Open 923 non-null float64
High 923 non-null float64
Low 923 non-null float64
Close 923 non-null float64
Volume 923 non-null int64
Adj Close 923 non-null float64
dtypes: float64(5), int64(1), object(1)
我试图将日期转换为字符串,但无论我尝试什么方法都不起作用。我尝试遍历行并使用str()进行转换。我尝试改变对象的dtype,使用
dt['Date'].apply(str)
,还尝试了特殊的dtype对象来进行转换:types={'Date':'str','Open':'float','High':'float','Low':'float','Close':'float','Volume':'int','Adj Close':'float'}
dt = pd.read_csv('data/Tesla.csv', dtype=types)
但是似乎什么都不起作用。
我使用的是 Pandas 版本 0.13.1。