I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:
1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu
In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.
Note: I am using Pandas.
object
, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes. $\endgroup$df.loc[1, 'new_column']= 'my_value'
. Then dodf['new_column'].map(type)
. You will see, that all but the first row containfloat
s. That is because the other rows containNaN
, which is afloat
and not astr
. Likewise you could mix in other object types in yourobject
column if you like (but it is probably not a very good idea). $\endgroup$