0

This was working yesterday, tried to do it with a new file today, and its providing this error.

I'm trying to drop rows that has specific characters (gifs, gif) in them within that column.

My code is

import pandas as pd

data = pd.read_csv("Hete Output.csv", index_col ="C")
  
# dropping passed values
data.drop(["gifs", "gif"], inplace = True)
data.to_csv("Hete Output 1.csv")

According to panda https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html?highlight=drop is claims the axis is either index or columns. So when I tried

data.drop(["gifs", "gif"], inplace = True, axis = "Any value/character here")

I would get Exception has occurred: ValueError No axis named [] for object type DataFrame

So I'm not sure how to go about this.

  • 1
    `axis` can only equal `0`, `1`, `index`, or `columns`, nothing else. – BeRT2me Jul 09 '22 at 22:41
  • @BeRT2me so would that mean I would have to eliminate the other columns until the index_col equates to 0 or 1? – IUseThisToAskForHelp Jul 09 '22 at 22:42
  • 1
    See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – BeRT2me Jul 09 '22 at 23:16
  • Consider using [`Series.str.contains`](https://pandas.pydata.org/docs/reference/api/pandas.Series.str.contains.html) to filter out rows with specific strings in specific column. – Parfait Jul 09 '22 at 23:23

1 Answers1

0
  • df.drop() is used to drop whole rows or whole columns.
  • To drop a column, you specify it by column name like: df.drop(['col_name'], axis=1)
  • To drop a row, you specify it by index value/number like: df.drop([0])
    • (This can be made dynamically with a mask)

It's not clear which of these you're actually trying to drop. If you update your question to include a working example of input and desired output, I can help you work that out.

BeRT2me
  • 12,699
  • 2
  • 13
  • 31
  • I'm trying to drop a row that has specific characters in their cells. I thought I could drop all rows that align within a specific column, then move to another column, that repeat that row drop. – IUseThisToAskForHelp Jul 09 '22 at 22:58
  • Please *show* what you mean, typing the same thing again isn't helping you be more clear. – BeRT2me Jul 09 '22 at 23:02
  • how should I show you to make it more clear because I'm not sure how to be more clear with what I'm trying to do. – IUseThisToAskForHelp Jul 09 '22 at 23:15
  • I can not run `pd.read_csv("Hete Output.csv", index_col ="C")`. Make an example that I *can* run. – BeRT2me Jul 09 '22 at 23:18