1function IsJsonString(str) {
2 try {
3 JSON.parse(str);
4 } catch (e) {
5 return false;
6 }
7 return true;
8}
1import numpy as np
2df['first_five_Letter']=df['Country (region)'].str.extract(r'(^w{5})')
3df.head()
4
1S=pd.Series(['Finland','Colombia','Florida','Japan','Puerto Rico','Russia','france'])
2[itm[0] for itm in S.str.findall('^[Ff].*') if len(itm)>0]
3
1#convert column to string
2df['movie_title'] = df['movie_title'].astype(str)
3
4#but it remove numbers in names of movies too
5df['titles'] = df['movie_title'].str.extract('([a-zA-Z ]+)', expand=False).str.strip()
6df['titles1'] = df['movie_title'].str.split('(', 1).str[0].str.strip()
7df['titles2'] = df['movie_title'].str.replace(r'\([^)]*\)', '').str.strip()
8print df
9 movie_title titles titles1 titles2
100 Toy Story 2 (1995) Toy Story Toy Story 2 Toy Story 2
111 GoldenEye (1995) GoldenEye GoldenEye GoldenEye
122 Four Rooms (1995) Four Rooms Four Rooms Four Rooms
133 Get Shorty (1995) Get Shorty Get Shorty Get Shorty
144 Copycat (1995) Copycat Copycat Copycat
15
1# Get countries starting with letter P
2S=pd.Series(['Finland','Colombia','Florida','Japan','Puerto Rico','Russia','france'])
3S[S.str.match(r'(^P.*)')==True]
4