Skip to content

QST: About the meaning of ~ used in dfs = dfs.loc[:, ~dfs.columns.str.contains('^Unnamed', na=False)]. #43832

@hongyi-zhao

Description

@hongyi-zhao

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/a/64335734

Question about pandas

Currently, I'm using the following method to get rid of Unnamed: 0 column in a pandas DataFrame according to the comments noted here and here:

import pandas as pd

excel='2021-2022-1.xlsx'
dfs = pd.read_excel(excel)
dfs = dfs.loc[:, ~dfs.columns.str.contains('^Unnamed', na=False)]

But I am puzzled by the meaning of the ~ symbol used above. I try to find some relevant explanations by googling or digging into the source code of pandas, but still got nothing. Any hints for this question will be greatly appreciated.

Regards,
HZ

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssue that has not been reviewed by a pandas team memberUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions