From strings in a dataframe
, is it possible to let the user know if there is an uneven number of double quotation marks?
Asked
Active
Viewed 48 times
-3

martineau
- 119,623
- 25
- 170
- 301
-
2`if s.count('"') % 2 == 1: print("Oh no!")`? For a dataframe, do it a bunch of times? – ShadowRanger Sep 22 '20 at 11:10
-
I would like to do this check for all columns in a dataframe – Jacob Liljestrand Sep 22 '20 at 11:38
-
Does this answer your question? [How to get value counts for multiple columns at once in Pandas DataFrame?](https://stackoverflow.com/questions/32589829/how-to-get-value-counts-for-multiple-columns-at-once-in-pandas-dataframe) – Tomerikoo Sep 22 '20 at 12:19
1 Answers
2
x = '"""'
print(x.count('"')%2==1)
output:
True

Yossi Levi
- 1,258
- 1
- 4
- 7
-
I would like to do this check for all columns in a dataframe – Jacob Liljestrand Sep 22 '20 at 11:38
-
post your code and I could try to help. you can sum-up all the `count` over the columns and then check if it's odd for example – Yossi Levi Sep 22 '20 at 11:45
-
Okey, how about just counting all " in a dataframe? How do I do that – Jacob Liljestrand Sep 22 '20 at 12:10
-
use this: `s = pd.Series(['$', 'B', 'Aab$', '$$ca', 'C$B$', 'cat']) s.str.count('"')`, and sum over the result – Yossi Levi Sep 22 '20 at 12:19