machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

DataFrame - Drop multiple columns

Open luisquintanilla opened this issue 3 years ago • 3 comments

luisquintanilla avatar Dec 01 '22 00:12 luisquintanilla

@luisquintanilla Is there currently a way to drop just one column?

awa5114 avatar Mar 27 '23 08:03 awa5114

@amine-aboufirass you can do the following currently:

// Drop the ID column
df.Columns.Remove("ID");

IntegerMan avatar Mar 09 '24 04:03 IntegerMan

A temporary workaround around removing multiple at once would be logic like this:

// Remove unnecessary columns
string[] columnsToDrop = new string[] { "first_name", "last_name", "name", "player_id", "index", "current_club_id", "player_code", "city_of_birth", "country_of_citizenship", "date_of_birth", "contract_expiration_date", "agent_name", "image_url", "url", "current_club_domestic_competition_id", "current_club_name" };
foreach (string columnName in columnsToDrop) {
    df.Columns.Remove(columnName);
}

You could wrap this into a static class with a static extension method that took in a params array of strings if you wanted, then you could call df.Remove("A", "B", "C"); via your extension method.

IntegerMan avatar Mar 10 '24 19:03 IntegerMan