0

I am dealing with the analysis of dataset stored in pandas data file, which has been defined in my Python programm as

df = pd.DataFrame(columns=["System","LogP", "Hb_acc", "Hb_donnors", "Weight"])

According to the folat: the first two columns correspond to the number of the system and its name, and the columns 3-6 to the measurements performed for these systems:

        System    LogP Hb_acc Hb_donnors   Weight
0        cne_1  1.1732      3          1  263.405
1       cne_10  2.6639      2          0  197.237
2      cne_100 -0.2886      4          2  170.193
3     cne_1000  1.9644      5          1  304.709
4     cne_1001  1.4986      3          1  162.144
...        ...     ...    ...        ...      ...
1033   cne_995  3.0179      4          2  347.219
1034   cne_996  4.8419      6          2  407.495
1035   cne_997  3.3560      3          1  354.524
1036   cne_998  7.5465      4          2  635.316
1037   cne_999  3.3514      4          1  389.556

I need to filter these 1037 lines, taking only the lines matched the following demands for ALL of the columns :

  • the third_column (LogP), should be < 5
  • the fouth_column (Hb_acc), should be <10
  • the fifth_column (Hb_donor), should be <5
  • the six_column (Weight), should be < 500

1 Answer 1

0

You need to look at the pandas.DataFrame.loc (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html) method. As an example, your first request could be found like this:

new_df = df.loc[df['LogP'] < 5]

While I haven't had a need to (yet), I'd bet you can chain these together and get what you need in one shot.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Actually I've made such filtering of DF considering all columns, using df_filter = df[(df['LogP'] < 5) & (df['Hb_acc'] < 10) & (df['Hb_donnors'] < 5) & (df['Weight'] < 500)] which is quite simular to your example. What is the .loc in you case ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.