我如何理解列类型是数值还是数值分类?
How can i understand whether the column type is numerical or numerical categorical?
我使用的数据框有分类列和数字列。例如;
a b
1 1
1.35 2
2.42 3
3 3
假设 b 是数值分类列。但有时某些索引可能会被删除。所以在这种情况下,我需要填充已删除的索引。如果我知道该列是分类的,那么我将用前一列的值填充空列。那么我如何理解该列是否是绝对的呢?
提前致谢。
现在遇到这个,我认为这应该是第一种方法:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.api.types.infer_dtype.html
您可以检查一列包含的所有唯一值并决定
#List unique values in the df['name'] column
df.name.unique()
Pandas 支持分类数据类型 dtype="category"
因此您可以将列的类型更改为类别,以便在进一步的计算中使用这些知识
一个简单的答案是通过 df.column.iloc[0]
查看该列的一个元素。
Pandas 将尝试从数据源中推断列的数据类型,一旦数据类型被推断出来,每一行的数据类型都是一致的。
我使用的数据框有分类列和数字列。例如;
a b
1 1
1.35 2
2.42 3
3 3
假设 b 是数值分类列。但有时某些索引可能会被删除。所以在这种情况下,我需要填充已删除的索引。如果我知道该列是分类的,那么我将用前一列的值填充空列。那么我如何理解该列是否是绝对的呢? 提前致谢。
现在遇到这个,我认为这应该是第一种方法:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.api.types.infer_dtype.html
您可以检查一列包含的所有唯一值并决定
#List unique values in the df['name'] column
df.name.unique()
Pandas 支持分类数据类型 dtype="category"
因此您可以将列的类型更改为类别,以便在进一步的计算中使用这些知识
一个简单的答案是通过 df.column.iloc[0]
查看该列的一个元素。
Pandas 将尝试从数据源中推断列的数据类型,一旦数据类型被推断出来,每一行的数据类型都是一致的。