Add Python items and show them? What should I do?

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

There are 6 Keyword items.

python

2022-09-20 11:34

1 Answers

I added a column for the first purchase and added value_counts for that column.

>>> import pandas as pd


>> df = pd.DataFrame ({"keyword": ["first purchase", "first love", "re-purchase", "re-purchase", "steel-purchase"]})
>>> df
  keyword
0 First purchase
First love
2 Repurchase
3 Repurchase
4 Steel ball
>>> df["first_buy"] = df["keyword"].str.contains ("first")
>>> df
  keyword  first_buy
0 First purchase True
1. First love, true
2 Repurchase False
3 Repurchase False
4. Strong Jaegu False
>>> df["first_buy"].value_counts()
False    3
True     2
Name: first_buy, dtype: int64
>>> 


2022-09-20 11:34

If you have any answers or tips


© 2022 pinfo. All rights reserved.