Last active
November 12, 2019 05:43
-
-
Save stefanthoss/5f2f82b7b7173e5336e53856ceb2004c to your computer and use it in GitHub Desktop.
List all columns of a DataFrame that contain a certain character at least once.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Input: | |
# a b c d e | |
# 0 Text Text NaN 0.0 5 | |
# 1 Text NaN 1.1.1.1 0.0 55 | |
# 2 Text.Text Text Text 0.4 555 | |
data = [ | |
{"a": "Text", "b": "Text", "d": 0, "e": 5}, | |
{"a": "Text", "c": "1.1.1.1", "d": 0, "e": 55}, | |
{"a": "Text.Text", "b": "Text", "c": "Text", "d": 0.4, "e": 555}, | |
] | |
df = pd.DataFrame(data) | |
[c for c in df.columns if (df[c].astype(str).str.find(".") > -1).any()] | |
# Output: | |
# ['a', 'd', 'c'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment