【发布时间】:2019-02-03 01:23:28
【问题描述】:
例如:
df = pd.DataFrame([[int(1),2,3],[int(5),6,'a'],[0.1,4,True]], columns = list("abc"))
df
a b c
0 1.0 2 3
1 5.0 6 a
2 0.1 4 True
(附带问题:为什么不声明 int 做任何事情?)
现在,df.dtypes 回归
a float64
b int64
c object
dtype: object
但实际上是否可以在一列中列出所有不同的数据类型?
喜欢
a int64, float64
b int64
c int64, str, bool
【问题讨论】:
-
@jpp,啊,级长。由于某种原因,我找不到关于 SO 的确切问题。 Prolly 因为我没有使用“子类型”这个词。谢谢!我不只是在寻找对象,所以它可能会有所不同。喜欢
include=[df[c].dtype for c in df.columns] -
我会有更好的解决方案,但不能直接回答(感谢 stackoverflow),对不起。
标签: python pandas dataframe types