machinelearning
machinelearning copied to clipboard
DataFrame - Drop multiple columns
@luisquintanilla Is there currently a way to drop just one column?
@amine-aboufirass you can do the following currently:
// Drop the ID column
df.Columns.Remove("ID");
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.