in Education by
I want to select rows from a DataFrame based on values in some column in pandas, How can I do it? I use this in SQL: SELECT * FROM table WHERE column_name = some_value Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
There are many methods to do it but personally I'll suggest you to use mask, for instance check this example: from pandas import DataFrame # Create data set q = {'Revenue':[200,112,221], 'Cost':[331,441,551]} df = DataFrame(q) # mask = Return True when the value in column "Revenue" is equal to 111 mask = df['Revenue'] == 112 print mask # Result: # 0 False # 1 True # 2 False # Name: Revenue, dtype: bool # Select * FROM df WHERE Revenue = 112 df[mask] # Result: # Cost Revenue # 1 441 112

Related questions

0 votes
    I have a dataset |category| cat a cat b cat a I'd like to be able to return something like (showing unique values ... cat a 2 cat b 1 Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    How do I get the index column name in python pandas? Here's an example dataframe: Index Title Column 1 Apples 1 ... how to do this? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I created a dataframe and column labels in pandas and I need to edit in order to replace the original column ... names. Please help? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I'm trying to get the number of rows of dataframe df with Pandas, and here is my code. Method 1: total_rows ... What am I doing wrong? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I want to get a list of the column headers from a pandas DataFrame. The DataFrame will come from user input so I don ... 'gdp', 'cap'] Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    How to delete a column in a DataFrame, currently I am using: del df['column_1'] this is working fine, ... expected df.column_name ? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    There is a DataFrame from pandas: import pandas as pd inp = [{'e2':20, 'e3':200}, {'e2':22,'e3':220}, { ... '] Can I do this in Pandas? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    import pandas as pd from itertools import combinations, product, permutations MH_P= ["Maria Herrera"] OP_P= ["Oscar ... i solve it? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a dataframe as below itm Date Amount 67 420 2012-09-30 00:00:00 65211 68 421 2012-09-09 00 ... solutions would be appreciated. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd ... anyone help with that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    def multiple_dfs(xyz_file, sheet, *args): row=2 writer = pd.ExcelWriter(xyz_file, engine='openpyxl') df = pd. ... help me over this? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Working with census data, I want to replace NaNs in two columns ("workclass" and "native-country") with the ... way to do this? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
0 votes
    I have a pandas data frame like: a b A 1 A 2 B 5 B 5 B 4 C 6 I want to group by the ... do something like this using pandas groupby? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I wish to divide pandas dataframe to 3 separate sets. I know by using train_test_split from sklearn.cross_validation, ... ? kindly help Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...