Reputation: 668
I'm handling huge data series which are consist of float
values and Pandas.Series type.
I executed following code in Python.
import pandas as pd
# Read the specific column from CSV file.
float_log_series = pd.read_csv('./data.csv', usecols=['float_log']).float_log
data_cut = pd.cut(float_log_series, 20)
However, I got following error.
TypeError: '<=' not supported between instances of 'float' and 'str'
This error mentions that the data series could include str
type data.
I would like to extract and remove this data.
How can I do that ?
Upvotes: 1
Views: 60
Reputation: 25239
Use pd.to_numeric
with option errors='coerce'
and dropna
Sample:
s = pd.Series(['a', 1, 3.4, 'c', 0, 2.0])
Out[24]:
0 a
1 1
2 3.4
3 c
4 0
5 2
dtype: object
s_out = pd.to_numeric(s, errors='coerce').dropna()
Out[29]:
1 1.0
2 3.4
4 0.0
5 2.0
dtype: float64
Upvotes: 3