Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14301

Python Pandas Removing Row based on some filter rules [duplicate]

$
0
0

enter image description here

so, i have csv files like image above, which i want create filter :if 'Bids'< 3 AND 'Price'> 149

then data should be deleted, like the image above, data number 2 should be deleted

i already try this approach but didnt get what i want,

def filter(csv_file, csv2_file):    df = pd.read_csv(csv_file, header=0, index_col=False)    #Convert 'Bid' and 'Price' columns to numeric type    df['Bids'] = pd.to_numeric(df['Bids'], errors='coerce')    df['Price'] = pd.to_numeric(df['Price'], errors='coerce')    # Apply filtering conditions    filtered_df = df[(df['Bids'] < 3) & (df['Price'] > 149)]    filtered_df.to_csv(csv2_file, index=False)

as the result, the new output csv file is removing all the data,

enter image description here

please review my code


Viewing all articles
Browse latest Browse all 14301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>