Hello I’m trying to check if string_1 = 'this example string'
contains a column value as a substring.
For example the first value in Col B
should be True
since 'example'
is a substring of string_1
<code>string_1 = 'this example string'
┌──────────────────┬───────────────┬────────────┐
│ Col A ┆ Col B ┆ Col C │
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str │
╞══════════════════╪═══════════════╪════════════╡
│ 448220 ┆ example ┆ 7101936801 │
│ 518398 ┆ 99999 ┆ 9999900091 │
│ 557232 ┆ 424570 ┆ 4245742060 │
└──────────────────┴───────────────┴────────────┘
</code>
<code>string_1 = 'this example string'
┌──────────────────┬───────────────┬────────────┐
│ Col A ┆ Col B ┆ Col C │
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str │
╞══════════════════╪═══════════════╪════════════╡
│ 448220 ┆ example ┆ 7101936801 │
│ 518398 ┆ 99999 ┆ 9999900091 │
│ 557232 ┆ 424570 ┆ 4245742060 │
└──────────────────┴───────────────┴────────────┘
</code>
string_1 = 'this example string'
┌──────────────────┬───────────────┬────────────┐
│ Col A ┆ Col B ┆ Col C │
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str │
╞══════════════════╪═══════════════╪════════════╡
│ 448220 ┆ example ┆ 7101936801 │
│ 518398 ┆ 99999 ┆ 9999900091 │
│ 557232 ┆ 424570 ┆ 4245742060 │
└──────────────────┴───────────────┴────────────┘
This is what I have tried so far but it’s returning the following error:
<code>
df=df.with_columns([(pl.col("Col B").apply(lambda x: x in string_1).alias('new_col'))])
AttributeError: 'Expr' object has no attribute 'apply'
</code>
<code>
df=df.with_columns([(pl.col("Col B").apply(lambda x: x in string_1).alias('new_col'))])
AttributeError: 'Expr' object has no attribute 'apply'
</code>
df=df.with_columns([(pl.col("Col B").apply(lambda x: x in string_1).alias('new_col'))])
AttributeError: 'Expr' object has no attribute 'apply'