简体   繁体   中英

dropping rows to a condition in a column with pandas

Im trying dropping rows to a condition in a column with pandas here is the example:

df1=df.drop(df[df['Service Type']=='Bwari'].index,inplace)
df1.head(100)

below is the error obtained from the sample

TypeError                                 Traceback (most recent call last)
<ipython-input-10-13556f0da0b1> in <module>
----> 1 df1=df.drop(df(df['Service Type']=="Bwari").inplace)
      2 df1.head(100)

TypeError: 'DataFrame' object is not callable

When you use "drop" pandas is expecting you to pass it the value of a column name, not a DataFrame. Every time you see an error like this "'DataFrame' object is not callable" it means you are passing the code the wrong object argument. For example, you should be able to do:

df = df.drop('Service Type')

However, this would drop the entire column, and would not be based on the condition you specified above.

I believe what you are trying to do can be accomplished with the following code:

df = df[df['Service Type']=='Bwari']]

I see you added df.head(100). If you are also looking to drop the first 100 rows, I would suggest the following code after you have redefined df:

df = df.iloc[100:]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM