Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

astype float across columns pandas

In [273]: cols = df.columns.drop('id')

In [274]: df[cols] = df[cols].apply(pd.to_numeric, errors='coerce')

In [275]: df
Out[275]:
     id    a  b  c  d  e    f
0  id_3  NaN  6  3  5  8  1.0
1  id_9  3.0  7  5  7  3  NaN
2  id_7  4.0  2  3  5  4  2.0
3  id_0  7.0  3  5  7  9  4.0
4  id_0  2.0  4  6  4  0  2.0

In [276]: df.dtypes
Out[276]:
id     object
a     float64
b       int64
c       int64
d       int64
e       int64
f     float64
dtype: object
Comment

astype float across columns pandas

cols = df.columns[df.dtypes.eq('object')]
Comment

PREVIOUS NEXT
Code Example
Python :: install python package 
Python :: List Comprehension iteration 
Python :: python gui framework 
Python :: python list intersection 
Python :: while loop with if else 
Python :: create pdf in python 
Python :: pyqt math 
Python :: how to run python code in python 
Python :: how to run class.function from name python 
Python :: get index of first true value numpy 
Python :: a function to create a null matrix in python 
Python :: class __call__ method python 
Python :: qr scanner 
Python :: python isdigit 
Python :: panda lambda function returns dataframe 
Python :: python message 
Python :: {"message": "401: Unauthorized", "code": 0} discord 
Python :: gtk label set label 
Python :: max value of a list prolog 
Python :: flask flash The browser (or proxy) sent a request that this server could not understand. 
Python :: pandas get row if difference previous 
Python :: add item to list python 
Python :: what does the .item() do in python 
Python :: dlib.shape_predictor 
Python :: remove timezone from a datetime object? 
Python :: replace by positions a string in a list with another string python 
Python :: remove all occurences 
Python :: __all__ python 
Python :: percentage plot of categorical variable in python woth hue 
Python :: drop columns pandas dataframe 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =