python - find position of string elements in pandas dataframe -


i have pandas data frame , suspect contains strings

>>> d2    1     2     3     4     5     6     7     8     9     10    ...   1771  \ 0     0     0     0     0     0     0     0     0     0     0  ...      0    1     0     0     0     0     0     0     0     0     0     0  ...      0    2     0     0     0     0     0     0     0     0     0     0  ...      0    3     0     0     0     0     0     0     0     0     0     0  ...      0    4     0     0     0     0     0     0     0     0     0     0  ...      0    5     0     0     0     0     0     0     0     0     0     0  ...      0    6     0     0     0     0     0     0     0     0     0     0  ...      0    7     0     0     0     0     0     0     0     0     0     0  ...      0    8     0     0     0     0     0     0     0     0     0     0  ...      0    9     0     0     0     0     0     0     0     0     0     0  ...      0        1772  1773  1774  1775  1776  1777  1778  1779  1780   0     0     0     0     0     0     0     1   398     2   1     0     0     0     0     0     0     1   398     2   2     0     0     0     0     0     0     1   398     2   3     0     0     0     0     0     0     1   398     2   4     0     0     0     0     0     0     1   398     2   5     0     0     0     0     0     0     1   398     2   6     0     0     0     0     0     0     1   398     2   7     0     0     0     0     0     0     1   398     2   8     0     0     0     0     0     0     1   398     2   9     0     0     0     0     0     0     1   398     2    [10 rows x 1780 columns] >>> any(d2.applymap(lambda x: type(x) == str)) true >>>   

i find elements string , in case remove columns containing these elements.

how can that?

i strange result. seems columns have dtype int or float @ same time seems elements string. how possible?

>>> d2.dtypes.drop_duplicates() 1         int64 1755    float64 dtype: object >>> any(d2.applymap(lambda x: type(x) == str)) true 

i getting false positives because of method use.

here do:

to select columns might have text use command:

df.select_dtypes(include=['object']).columns 

or alternatively:

df.select_dtypes(exclude=['number']).columns 

to check if cell in dataframe text use command:

df.applymap(lambda x: isinstance(x, str)).any().any() 

or drop last .any() see columns have text , don't:

df.applymap(lambda x: isinstance(x, str)).any() 

calling any(your_dataframe) (with dataframe parameter) gives false positive.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -