How do i add an extra column in a dataframe, so it could split and convert to integer types but np.nan for string types
Col1
1|2|3
"string"
so
Col1 ExtraCol
1|2|3 [1,2,3]
"string" nan
I tried long contorted way but failed
df['extracol'] = df["col1"].str.strip().str.split("|").str[0].apply(lambda x: x.astype(np.float) if x.isnumeric() else np.nan).astype("Int32")