I want to check if a column in a dataframe contains rows. I would have thought it could be done just by checking dtype, but that is not the case. The pandas series containing strings only has a dtype object, which is also used for other data structures (e.g. lists):
df = pd.DataFrame({'a': [1,2,3], 'b': ['Hello', '1', '2'], 'c': [[1],[2],[3]]}) df = pd.DataFrame({'a': [1,2,3], 'b': ['Hello', '1', '2'], 'c': [[1],[2],[3]]}) print(df['a'].dtype) print(df['b'].dtype) print(df['c'].dtype)
It produces:
int64 object object
Is there a way to check if a column contains only rows?
source share