7 kyu

Pandas Series 103: Filter Rows From DataFrames That Don't Satisfy Condition

Description
Loading description...
Data Frames
Fundamentals
Data Science
  • Please sign in or sign up to leave a comment.
  • RileyHunter Avatar

    The initial solution given raises a NameError (df in the column check vs dataframe in the parameter list).

    Fork rectifying this: https://www.codewars.com/kumite/666a794ebccbd79f03486250

  • dfhwze Avatar

    Who votes 2 kyu here, this can't be in good faith :/

  • Ruslan-dev-Free-Fire Avatar

    This kata does not describe how to handle cases where the target column does not exist in the DataFrame. Adding a check for the presence of a column and an associated error message would improve the feature.

    Overall, the challenge provides a good starting point for practicing working with the pandas library and filtering data in a DataFrame, but some additional detail and testing could make it more complete.

  • Zachj345 Avatar

    I would def be more clear in the description on what you want for the user. I had to check the expected output to understand what you were going for. But all in all great kata!

  • __eloise__ Avatar

    A couple small suggestions for description clarity:

    • "Contidion" in title -> "Condition"
    • "Your function must return a new pandas.DataFrame object with same data and columns than the original input. Only the rows whose cell values in designated column after the filter are evaluated as False should appear in the result." -> Your function must return a new pandas.DataFrame object with the same columns as the original input. However, include only the rows whose cell values in the designated column evaluate to False by func."
  • Voile Avatar

    The functions passed in the random tests is like this:

    lambda x,a,b: a<x and x<b
    

    which is completely against the idiomatic practice in pandas. (In fact this causes the idiomatic practice fail the random tests.) pandas uses | and & in place of or and and.

  • FArekkusu Avatar

    Value is not what was expected

    Same damn issue. Could you learn how to write tests before authoring these?

    • albertogcmr Avatar

      something like this?

      test.expect(user_solution.equals(expected_solution), f"{user_solution}\nShould be\n{expected_solution}")
      
    • FArekkusu Avatar

      Yes, but you probably should also compare dtype's to make it easier for the users.

    • albertogcmr Avatar

      Thanks. Now I think it is done.

      test.expect(user_solution.dtypes.equals(expected_solution.dtypes), f"{user_solution.dtypes}\nShould be\n{expected_solution.dtypes}")
      test.expect(user_solution.equals(expected_solution), f"{user_solution}\nShould be\n{expected_solution}")
      
    • FArekkusu Avatar

      It'd be good if you designated somehow what is being tested. And IMO the dataframes should be compared only if the dtype test passed.

    • albertogcmr Avatar

      It'd be good if you designated somehow what is being tested i don't undestand this.

    • FArekkusu Avatar

      Fixed.

      Issue marked resolved by FArekkusu 5 years ago
    • ggorlen Avatar

      While these improvements are a good step above no error message, using pd.testing.assert_frame_equal might give better results still since it covers errors on every possible dimension with corresponding pretty prints and messages.

    • albertogcmr Avatar

      It could be a good idea. @FArekkusu has given pretty good feedback and has more experience that me in kata creation.