goaty
goaty

Reputation: 163

Column Filtering With Python

This is my dataframe enter image description here

I want to filter the Market Cap column to only show data above 40,000,000 and delete the rest but Im getting an error each time I try the usual column filtring methods.

TypeError: '<=' not supported between instances of 'str' and 'int'

df = df.set_index('Symbol')
df = df.dropna(how='all').dropna()
df['MarketCap'] = df['MarketCap'].apply(lambda x: '{:.2f}'.format(x))
df["MarketCap"] <= 40000000

Upvotes: 0

Views: 62

Answers (1)

Yuan JI
Yuan JI

Reputation: 2995

Try .loc, then convert to str:

df = df.loc[df["MarketCap"] >= 40000000]
df['MarketCap'] = df['MarketCap'].apply(lambda x: '{:.2f}'.format(x))

Upvotes: 1

Related Questions