Hi,
is it possible to remove a row in a dataframe in C#. (I use Microsoft.Data.Analysis library).
Thanks in advance for your answers.
Best regards,
Hi,
is it possible to remove a row in a dataframe in C#. (I use Microsoft.Data.Analysis library).
Thanks in advance for your answers.
Best regards,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Uday DodiyaRank #239 · 10.3K reputationPosted Jan 27, 2023, 4:46 AM EST
You can use the
RemoveRow()method to remove a specific row by passing the index of the row you want to remove. Here is an example:using Microsoft.Data.Analysis; DataFrame df = new DataFrame(); // Add data to the DataFrame df.RemoveRow(index);Alternatively, you can use the
Remove()method to remove a specific row using a lambda expression that specifies the condition for the row you want to remove. Here is an example:df.Remove(r => r[0] == "some value");It will remove all the rows that meet the condition inside the lambda expression.
Keep in mind that the Remove method and RemoveRow method will remove the rows from the Dataframe permanently and you cannot undo the operation.
Eric KUHM25 reputationPosted Jan 27, 2023, 5:44 AM EST
Thanks for the answer but I get an error: there is no definition for extension method 'RemoveRow'.
I'm using Microsoft.Data.Analysis version 0.20.0
best regards,
Uday DodiyaRank #239 · 10.3K reputationPosted Jan 27, 2023, 11:17 PM EST
the version of the Microsoft.Data.Analysis library you are using (0.20.0) does not include a method called 'RemoveRow' for DataFrame objects.
Instead you can use the
Dropmethod like this:This will drop the row at index
indexfrom the DataFrame.Alternatively, you can use the
Rows.RemoveAt()method like this:This will remove the row at index
indexfrom the DataFrame.Note that both
Drop()andRows.RemoveAt()methods will permanently remove the rows from the DataFrame, and the changes made to the DataFrame will be reflected in the original DataFrame.