I have a DataFrame with two columns. One column contain string values that may or may not include numbers (integer or float).
Sample:
import pandas as pd
import numpy as np
data = [('A', '>10'),
('B', '10'),
('C', '<10'),
('D', '10'),
('E', '10-20'),
('F', '20.0'),
('G', '25.1') ]
data_df = pd.DataFrame(data, columns = ['name', 'value'])
Entries in Column value have string data-type. But, their values might be numeric or not.
What I want to get:
Find which rows have numeric values in column
value.Remove other rows from dataset.
Final result will look like:
name value
'B' 10
'D' 10
'F' 20.0
'G' 25.1
I tried to use isnumeric() function but it returns True only for integers (not float).
If you have any idea to solve this problem, please let me know.
Updated Question (multi columns):
(The same question when there are more than one column with numeric values)
Similarly, I have a DataFrame with three columns. Two columns contain string values that may or may not include numbers (integer or float).
Sample:
import pandas as pd
import numpy as np
data = [('A', '>10', 'ABC'),
('B', '10', '15'),
('C', '<10', '>10'),
('D', '10', '15'),
('E', '10-20', '10-30'),
('F', '20.0', 'ABC'),
('G', '25.1', '30.1') ]
data_df = pd.DataFrame(data, columns = ['name', 'value1', 'value2'])
Entries in Columns value1 & value2 have string data-type. But, their values might be numeric or not.
What I want to get:
Find which rows have numeric values in columns
value1&value2.Remove other rows from dataset.
Final result will look like:
name value1 value2
'B' 10 15
'D' 10 15
'G' 25.1 30.1