Filtering rows of pandas data frame by column value without specifying column name

user

I am trying to filter the rows of a data frame where the last column is less than 4, without specifying the column name. [See this question for context on data frame] (Convert the last column of a data frame from hex to decimal)

I used the solution provided by @not_speshal but I am getting this error. TypeError: '>=' not supported between instances of 'str' and 'int'. How can I fix it?

Muhteva

The solution is wrong. When you use this one:

df[df.columns[-2]<=4]

What you do is to compare the name of the column at index -2 with 4. Like "Color" > 4, which gives an error. Try this one:

df[df[df.columns[-2]]<=4]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Replicating rows in a pandas data frame by a column value

Filtering rows in a data frame based on date column

how to concatenate all rows of a column of a data frame in pandas without group by

How do I group the rows of a pandas data frame by a value of a column?

pandas data frame find all rows with particular column value?

Change value of all rows in a column of pandas data frame

python pandas data-frame - duplicate rows according to a column value

Repeat rows in pandas data frame with a sequential change in a column value

Create an empty data.frame without specifying column names

Assigning data frame name to all rows in a column

Given a column value, check if another column value is present in preceding or next 'n' rows in a Pandas data frame

Extracting rows from a data frame with respect to the bin value from other data frame(without using column names)

Merge rows of pandas data frame by grouping a column

filtering rows in data.frame where column values are inconsistent

Splitting pandas data frame based on column name

Reform Pandas Data frame based on column name

Map new column name to a data frame in Pandas

Filtering a data frame by column names

How can I compare a column in a data frame by a value in a column with the same name/place in a second dataframe in Pandas?

Assign value in Data Frame Column without Loop

why all() without arguments on a data frame column(series of object type) in pandas returns last value in a column

Filtering a pandas data frame which has 2 level of column headers

Renaming data frame column variables without using column name

Filtering all rows with a specific value, without specifiying column names

Selecting a random value in a pandas data frame by column

Pandas group data frame and sort by column value

Python Pandas: Merge Columns of Data Frame with column name into one column

Filtering rows that have unique value in a column using pandas

Python Pandas filtering rows based on column value returns NaN