Skip to main content
本文に 132 文字追加
ソース リンク
metropolis
  • 6,705
  • 2
  • 6
  • 16
import pandas as pd

df = pd.DataFrame({
    'product': ['a', 'b', 'c', 'd'],
    'column_a': ['17,117,217', '17', '117', '217'],
})

print(df[df['column_a'].str.contains(r'\b17\b')])

#
  product    column_a
0       a  17,117,217
1       b          17

pandas.Series.str.split + set.issubset

print(df[df['column_a'].str.split(',').map({'17'}.issubset)])
import pandas as pd

df = pd.DataFrame({
    'product': ['a', 'b', 'c', 'd'],
    'column_a': ['17,117,217', '17', '117', '217'],
})

print(df[df['column_a'].str.contains(r'\b17\b')])

#
  product    column_a
0       a  17,117,217
1       b          17
import pandas as pd

df = pd.DataFrame({
    'product': ['a', 'b', 'c', 'd'],
    'column_a': ['17,117,217', '17', '117', '217'],
})

print(df[df['column_a'].str.contains(r'\b17\b')])

#
  product    column_a
0       a  17,117,217
1       b          17

pandas.Series.str.split + set.issubset

print(df[df['column_a'].str.split(',').map({'17'}.issubset)])
ソース リンク
metropolis
  • 6,705
  • 2
  • 6
  • 16

import pandas as pd

df = pd.DataFrame({
    'product': ['a', 'b', 'c', 'd'],
    'column_a': ['17,117,217', '17', '117', '217'],
})

print(df[df['column_a'].str.contains(r'\b17\b')])

#
  product    column_a
0       a  17,117,217
1       b          17