简体   繁体   中英

How to search for a string pattern and print the total values in a column using pandas

Market  Region  No_of_Orders    Profit  Sales
Africa  Western Africa  251 -12,901.51  78,476.06
Afr3ica Southern Africa 85  11,768.58   51,319.50
Africa  North Africa    182 21,643.08   86,698.89
Afr2ica Eastern Africa  110 8,013.04    44,182.60
Africa  Central Africa  103 15,606.30   61,689.99
Eur1ope Western Europe  964 82,091.27   656,637.14
EurYope Southern Europe 338 18,911.49   215,703.93

How to filter and print the total market values which have typos !! I tried like this

-->result['Market'].str.contains(u'\|123\|').count()
masked = df['Market'].str.contains("1|2|3")

to filter:

print(df[masked])

to count:

print(masked.sum())

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