This is a struggle record of knocking 100 eggs without knowing the data scientist's egg. It is a mystery whether I can finish the race. ~~ Even if it disappears on the way, please think that it is not given to Qiita. ~~
100 knock articles 100 Knock Guide
** Be careful if you are trying to do it as it includes spoilers **
This time from 10 to 18 First time with table of contents
From this time on, things I wrote are not always successful, and I am writing while looking at the answers and writing examples of failures.
mine10.py
df=df_store
df[df['store_cd'].str.contains('S14')].head()
'''Model answer'''
df_store.query("store_cd.str.startswith('S14')", engine='python').head(10)
'''Failure example'''
import re
df=df_store
df[None != re.match(r'S14.*',str(df['store_cd']))]
#>(Omission)KeyError: False
** At first glance, I thought, "If you use LIKE with SQL, it's one shot !?" ** ** For the time being, I try to solve it by plunging into ~~ heart friend ~~ rematching. However, I noticed that it was not a character string type, and even if I matched the first character with this writing method, it did not return with None ~ ~ I kept causing KeyError in the first place ~ ~ I searched for another means.
Then, I found something called df.str.contains and was impressed.
I used it while feeling invincible because I could write the inside with regular expressions, but I used the model answer ~~ and the Wakanowakaranai ~~ method.
ʻEngine ='python'` seems to be a magical thing [reference]
mine11.py
df=df_customer
df[df['customer_id'].str.contains('1$')].head()
'''Model answer'''
df_customer.query("customer_id.str.endswith('1')", engine='python').head(10)
A problem that continues to tell us the value of SQL.
After writing the article to some extent and reviewing it, read the reference again and check the method below df.str.
mine12.py
df= df_store
df=df[df['address'].str.contains('Yokohama')]
df
'''Model answer'''
df_store.query("address.str.contains('Yokohama')", engine='python')
mine13.py
df=df_customer
df=df[df['status_cd'].str.contains('^[A-F]')]
df.head(10)
'''Model answer'''
df_customer.query("status_cd.str.contains('^[A-F]', regex=True)", engine='python').head(10)
mine14.py
df=df_customer
df=df[df['status_cd'].str.contains('[0-9]$')]
df.head(10)
'''Model answer'''
df_customer.query("status_cd.str.contains('[1-9]$', regex=True)", engine='python').head(10)
mine15.py
df=df_customer
df=df[df['status_cd'].str.contains('^[A-F].*[0-9]$')]
df.head(10)
'''Model answer'''
df_customer.query("status_cd.str.contains('^[A-F].*[1-9]$', regex=True)", engine='python').head(10)
mine16.py
df=df_store
df=df[df['tel_no'].str.contains('[0-9]{3}-[0-9]{3}-[0-9]{4}')]
df.head(10)
'''Model answer'''
df_store.query("tel_no.str.contains('[0-9]{3}-[0-9]{3}-[0-9]{4}', regex=True)", engine='python')
I'm sorry I have no impression. I'm sorry I didn't use query. ~~ I'm scared because I don't throw an error while writing ~~
In addition, regex = True seems to mean" use regular expressions "[reference]
mine17.py
df_customer.sort_values('birth_day', ascending=True).head(10)
I forgot about this, so I wrote it while checking it.
Does ʻascending mean the same as SQL ʻORDER BY ASC?
mine17.py
df_customer.sort_values('birth_day', ascending=False).head(10)
The difference from SQL is that instead of using DESC, ʻascending = False`.
1 and 2 were reviews with a feeling of a digestive game, but from here on, the question of whether or not knowledge can be combined will increase. ~~ I don't have enough knowledge ~~ I had many difficult problems, so I want to proceed at a slightly slower pace. There are some parts to skip (21,22, etc.).