如果我创建一个数据框,其中一列是对象,另一列是整数,将该数据框放入字典中,然后使用该字典创建面板,整数数据类型消失:
import pandas as pd
import datetime as dt
a=['a' for i in range(1000)]
b=[i for i in range(1000)]
c = {'c':a[:], 'b':b[:]}
df = pd.DataFrame(c)
print df
d = dict()
d['x'] = df
p = pd.Panel(d)
print p['x']
输出:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1000 entries, 0 to 999
Data columns (total 2 columns):
b 1000 non-null values
c 1000 non-null values
dtypes: int64(1), object(1)
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1000 entries, 0 to 999
Data columns (total 2 columns):
b 1000 non-null values
c 1000 non-null values
dtypes: object(2)
从包含 DataFrame 的字典创建面板时,有没有办法保留数据类型?