[Python] 100 knocks on data science (structured data processing) 016 Explanation

Youtube Video commentary is also available.

problem

P-016: From the store data frame (df_store), display all items with 3 digits-3 digits-4 digits for the phone number (tel_no).

answer

code


df_store.query("tel_no.str.contains('[0-9]{3}-[0-9]{3}-[0-9]{4}')", engine='python')

output

store_cd store_name prefecture_cd prefecture address address_kana tel_no longitude latitude floor_area
0 S12014 Chigusadai store 12 Chiba 1-chome, Chigusadai, Inage-ku, Chiba-shi, Chiba Chiba Ken Chiba Shiinagekuchigusadai Itchoume 043-123-4003 140.118 35.63559 1698
1 S13002 Kokubunji store 13 Tokyo 2-chome Honda, Kokubunji-shi, Tokyo Tokyo Kokubunji Kokubunji 042-123-4008 139.4802 35.70566 1735
2 S14010 Kikuna store 14 Kanagawa Prefecture 1-chome, Kikuna, Kohoku-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Shikou Hokukuki Kunai Choume 045-123-4032 139.6326 35.50049 1732
3 S14033 Akuwa store 14 Kanagawa Prefecture 1-chome, Akuwanishi, Seya-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Seya Kakuwanishi Itchoume 045-123-4043 139.4961 35.45918 1495
4 S14036 Sagamihara Chuo store 14 Kanagawa Prefecture Chuo 2-chome, Sagamihara City, Kanagawa Prefecture Kanagawa Kensagamihara Shichuo Unichoume 042-123-4045 139.3716 35.57327 1679
7 S14040 Nagatsuta store 14 Kanagawa Prefecture 5-chome, Nagatsutaminamidai, Midori-ku, Yokohama-shi, Kanagawa Ken Kanagawa Yokohama Midori Ward Hall Ivy Minami Daigochoume 045-123-4046 139.4994 35.52398 1548
9 S14050 Akuwanishi store 14 Kanagawa Prefecture 1-chome, Akuwanishi, Seya-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Seya Kakuwanishi Itchoume 045-123-4053 139.4961 35.45918 1830
11 S13052 Morino store 13 Tokyo 3-chome Morino, Machida-shi, Tokyo Tokyo Tomachida Shimorino Sanchoume 042-123-4030 139.4383 35.55293 1087
12 S14028 Futatsubashi store 14 Kanagawa Prefecture Futatsubashi-cho, Seya-ku, Yokohama-shi, Kanagawa Ken Kanagawa Yokohama Seya Ward Office Futatsubashicho 045-123-4042 139.4963 35.46304 1574
16 S14012 Honmokuwada store 14 Kanagawa Prefecture Honmokuwada, Naka-ku, Yokohama City, Kanagawa Prefecture Kanagawa Ken Yokohama Shinakakuhon Mokuwada 045-123-4034 139.6582 35.42156 1341
18 S14046 Kitayamada store 14 Kanagawa Prefecture 1-chome, Kitayamata, Tsuzuki-ku, Yokohama-shi, Kanagawa Ken Kanagawa Yokohama Tsuzuki Ward Hall Tsuzuki Ward Hall 045-123-4049 139.5916 35.56189 831
19 S14022 Zushi store 14 Kanagawa Prefecture 1-chome, Zushi, Zushi City, Kanagawa Prefecture Kanagawa Kenzushi Shizushi Ichoume 046-123-4036 139.5789 35.29642 1838
20 S14011 Hiyoshihoncho store 14 Kanagawa Prefecture 4-chome, Hiyoshihoncho, Kohoku-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Shiko Hoku Hiyoshi Honcho Yonchome 045-123-4033 139.6316 35.54655 890
21 S13016 Koganei store 13 Tokyo 1-chome, Honcho, Koganei-shi, Tokyo Tokyo Koganei Hongcho Ichoume 042-123-4015 139.5094 35.70018 1399
22 S14034 Kawasaki Nogawa store 14 Kanagawa Prefecture Nogawa, Miyamae Ward, Kawasaki City, Kanagawa Prefecture Kanagawa Kenkawa Sakimiyama Ekunogawa 044-123-4044 139.5998 35.57693 1318
26 S14048 Nakagawa Chuo store 14 Kanagawa Prefecture Nakagawa Chuo 2-chome, Tsuzuki-ku, Yokohama-shi, Kanagawa Ken Kanagawa Yokohama Shitsuzuki Kunakagawa Chuo Unichoume 045-123-4051 139.5758 35.54912 1657
27 S12007 Sakura store 12 Chiba Kamishizu, Sakura City, Chiba Prefecture Chiba Ken Sakura Shikami Shizu 043-123-4001 140.1452 35.71872 1895
28 S14026 Tsujido West Coast Store 14 Kanagawa Prefecture 2-chome, Tsujidonishikaigan, Fujisawa City, Kanagawa Prefecture Kanagawa Ken Fujisawa Shitsuji Dounishi Kaigan Nichome 046-123-4040 139.4466 35.32464 1732
29 S13041 Hachioji store 13 Tokyo Otsuka, Hachioji, Tokyo Tokyo Hachioji Ujisio Otsuka 042-123-4026 139.4235 35.63787 810
31 S14049 Kawasaki Daishi store 14 Kanagawa Prefecture 3-chome Nakaze, Kawasaki-ku, Kawasaki-shi, Kanagawa Kanagawa Ken Kawasaki Kawasaki Kunakaze Sanchoume 044-123-4052 139.7327 35.53759 962
32 S14023 Kawasaki store 14 Kanagawa Prefecture 2-chome, Honcho, Kawasaki-ku, Kawasaki-shi, Kanagawa Kanagawa Ken Kawasaki Kawasaki Kuhoncho Nichome 044-123-4037 139.7028 35.53599 1804
33 S13018 Kiyose store 13 Tokyo 1-chome, Matsuyama, Kiyose-shi, Tokyo Tokyo Tokiyoshi Matsuyamai 042-123-4017 139.5178 35.76885 1220
35 S14027 Minamifujisawa store 14 Kanagawa Prefecture Minamifujisawa, Fujisawa City, Kanagawa Prefecture Kanagawa Ken Fujisawa Shiminami Fujisawa 046-123-4041 139.4896 35.33762 1521
36 S14021 Isehara store 14 Kanagawa Prefecture 4-chome, Isehara, Isehara City, Kanagawa Prefecture Kanagawa Ken Isehara Shiisehara Yonchoume 046-123-4035 139.3129 35.40169 962
37 S14047 Sagamihara store 14 Kanagawa Prefecture 6-chome, Chiyoda, Sagamihara City, Kanagawa Prefecture Kanagawa Kensagami Harashi Chiyoda Rokuchoume 042-123-4050 139.3748 35.55959 1047
38 S12013 Narashino store 12 Chiba 1-chome, Shibazono, Narashino City, Chiba Prefecture Chiba Kennarashi no Shishi Bazono Ichoume 047-123-4002 140.022 35.66122 808
40 S14042 Shinyamashita store 14 Kanagawa Prefecture 2-chome, Shinyamashita, Naka-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Shinakakushin Yamashitani Chome 045-123-4047 139.6593 35.43894 1044
42 S12030 Yawata store 12 Chiba 3-chome, Yawata, Ichikawa-shi, Chiba Cibaken Ichikawa Shiyawata Sanchoume 047-123-4005 139.924 35.72318 1162
44 S14025 Yamato store 14 Kanagawa Prefecture Shimowada, Yamato City, Kanagawa Prefecture Ken Kanagawa Yamato Shishimo Wada 046-123-4039 139.468 35.43414 1011
45 S14045 Atsugi store 14 Kanagawa Prefecture 2-chome Nakacho, Atsugi City, Kanagawa Prefecture Kanagawa Ken Atsugi Shinakacho Nichoume 046-123-4048 139.3651 35.44182 980
47 S12029 Higashino store 12 Chiba 1-chome Higashino, Urayasu City, Chiba Prefecture Chiba Ken Urayasushi Higashino Itchoume 047-123-4004 139.8968 35.65086 1101
49 S12053 Takasu store 12 Chiba 5-chome Takasu, Urayasu City, Chiba Prefecture Chibaken Urayasushitakasugochome 047-123-4006 139.9176 35.63755 1555
51 S14024 Sanda store 14 Kanagawa Prefecture 4-chome, Mita, Tama-ku, Kawasaki-shi, Kanagawa Kanagawa Ken Kawasaki Takuma Tayon Chome 044-123-4038 139.5424 35.6077 972
52 S14006 Kuzugaya store 14 Kanagawa Prefecture Kuzugaya, Tsuzuki-ku, Yokohama-shi, Kanagawa Kanagawa Ken Yokohama Tsuzuki Ward Hall 045-123-4031 139.5633 35.53573 1886

Commentary

**-This is a method to check the data that meets the conditions in Pandas DataFrame / Series. -Use when you want to check the information that meets the conditions. -'Contains ()' is a function that determines whether the specified character string is included. If it is included, it returns True, and if it is not included, it returns False. -However,'.query ('column name.str.contains ())' is specified on condition that the specified character string is included. -In this case, use'tel_no.str'to replace tel_no with a character string, and'.contains ('[0-9] {3}-[0-9] {3}-[0-9] { By continuing 4}')', 3 out of [0-9], 3 out of'-', [0-9], 4 out of'-', [0-9] A character string such as a number is specified. -'[]' Is a regular expression that represents a range, and'-' specifies a range of consecutive values. '{}' Is a regular expression that represents the number of repetitions. ** **

** * For regular expressions, this article will be helpful. ** ** https://qiita.com/hiroyuki_mrp/items/29e87bf5fe46de62983c

** ・ For'engine ='python'', you can select'python' or'numexpr' for engine which is the argument of query, but when using str, specify'python'. If you do not give it, an error will occur. ** **

Recommended Posts

[Python] 100 knocks on data science (structured data processing) 018 Explanation
[Python] 100 knocks on data science (structured data processing) 023 Explanation
[Python] 100 knocks on data science (structured data processing) 030 Explanation
[Python] 100 knocks on data science (structured data processing) 022 Explanation
[Python] 100 knocks on data science (structured data processing) 017 Explanation
[Python] 100 knocks on data science (structured data processing) 016 Explanation
[Python] 100 knocks on data science (structured data processing) 024 Explanation
[Python] 100 knocks on data science (structured data processing) 027 Explanation
[Python] 100 knocks on data science (structured data processing) 029 Explanation
[Python] 100 knocks on data science (structured data processing) 015 Explanation
[Python] 100 knocks on data science (structured data processing) 028 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-007 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-006 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-001 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-002 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 021 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-005 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-004 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 020 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 025 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-003 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 019 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 001-010 Impressions + Explanation Link Summary
Try "100 knocks on data science" ①
Getting started with Python with 100 knocks on language processing
Preparing to try "Data Science 100 Knock (Structured Data Processing)"
Challenge 100 data science knocks
Data science 100 knock (structured data processing) environment construction (Windows10)
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 2]
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 1]
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 3]
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 5]
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 4]
That's why I quit pandas [Data Science 100 Knock (Structured Data Processing) # 6]
Start data science on the cloud
Image processing with Python 100 knocks # 2 Grayscale
Image processing with Python 100 knocks # 8 Max pooling
I took Udemy's "Practical Python Data Science"
Image processing with Python 100 knocks # 7 Average pooling
Video processing using Python + OpenCV on Mac
Image processing with Python 100 knocks # 9 Gaussian filter
Books on data science to read in 2020
Periodically execute Python Script on AWS Data Pipeline
Folium: Visualize data on a map with Python
[Data science memorandum] Handling of missing values ​​[python]
Try importing MLB data on Mac and Python
TensorFlow: Run data learned in Python on Android
Run Python on Apache to view InfluxDB data
100 language processing knocks 03 ~ 05
100 language processing knocks (2020): 40
100 language processing knocks (2020): 32
[Python] Challenge 100 knocks! (015 ~ 019)
100 language processing knocks (2020): 35
python image processing
100 language processing knocks (2020): 47
100 language processing knocks (2020): 39
Python on Windows
twitter on python3
100 language processing knocks (2020): 22
[Python] Challenge 100 knocks! (030-034)
Data analysis python