简体   繁体   中英

In pandas, how do you filter a column based on a specific string value

I have a pandas data frame that looks like:


Col 1
100
$50
200
$250
40
$400

How do I go about filtering the '$' and the non '$' values into their own specific columns?

mask = df.Col.str.startswith("$")

df2["col1"] = df[mask]
df2["col2"] = df[~mask]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM