How To Apply Filter Condition In Percentage String Column Using Pandas?
I am working on below df but unable to apply filter in percentage field,but it is working normal excel. I need to apply filter condition > 100.00% in the particular field using
Solution 1:
I am assuming that the values you have are read as strings in Pandas:
data = ['4,700.00%', '3,900.00%', '1,500.00%', '1,400.00%', '1,200.00%', '0.15%', '0.13%', '0.12%', '0.10%', '0.08%', '0.07%']
df = pd.DataFrame(data)
df.columns = ['data']
printing the df:
data04,700.00%
13,900.00%
21,500.00%
31,400.00%
41,200.00%
50.15%
60.13%
70.12%
80.10%
90.08%
100.07%
then:
df['data'] = df['data'].str.rstrip('%').str.replace(',','').astype('float')
df_filtered = df[df['data'] > 100]
Results:
data04700.013900.021500.031400.041200.0Solution 2:
I have used below code as well.str.rstrip('%') and .str.replace(',','').astype('float') it working fine
Post a Comment for "How To Apply Filter Condition In Percentage String Column Using Pandas?"