How can I delete a specific row and column pointing to a cell from a dataframe having a special character in Python?

Question:

For example, the dataframe is:

data = [['@Why', 1, 2], ['Stack', 1 ,'Example'], ['Overflow', 2, 'Anything'], ['row&', 3, 'Group' ]]
df = pd.DataFrame(data, columns=['A', 'B', 'C'])

From here I want to delete the @why and row& rows, but I want to keep the rows and columns data the same, like it should not delete the entire row or column. It should only delete the cell value.

Asked By: David

||

Answers:

Code:

df['A'] = df['A'].apply(lambda x: '' if any(c in "!@#$%^&*()-+?_=,<>/" for c in x) else x)
df

Output:

        A       B   C
0               1   2
1   Stack       1   Example
2   Overflow    2   Anything
3               3   Group
Answered By: Stackpy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.