我有一个如图所示的数据帧。我想使用apply/map/applymap获取每行和列的数据类型。
如何获得此数据类型?一些列具有混合的数据类型,如高亮显示的列表和字符串,一些列具有列表和字典。
def check_type(x):
try:
return type(eval(x))
except Exception as e:
return type(x)
df.applymap(check_type)
df.applymap(type).value_counts()
如果你想获取整个数据框的值而不是按列获取
np.unique(df.applymap(type).astype(str).values, return_counts=True)
df[df.isin(["<class 'dict'>", "<class 'list'>"]).any(axis=0)]
。 - alparslan mimaroğlu