from pandas import *
In [2]:
d = { 'one' : Series(['city_0', 'city_1']), 'two' : Series(['user_0', 'user_1'])}
df = DataFrame(d)
df
Out[2]:
In [3]:
df['one'].str.split('_')
Out[3]:
In [4]:
type(df['one'].str.split('_')) #Series that contain indices and String List
Out[4]:
In [6]:
df['one'].str.contains('1') #Check If There is '1' in each rows
Out[6]:
In [8]:
df['one'].str.replace('_', '##')
Out[8]:
In [9]:
df['one'].str.extract('(_[0-9])')
Out[9]:
In [11]:
movies = read_csv("./ml/movies.csv")
In [12]:
movies.head()
Out[12]:
In [18]:
movies['genres'].str.split("|", expand = True).head()
Out[18]:
In [20]:
movie_genres = movies['genres'].str.split("|", expand = True)
movie_genres['isComedy'] = movies['genres'].str.contains('Comedy')
In [21]:
movie_genres[ : 10]
Out[21]:
In [22]:
movies[:5]
Out[22]:
In [28]:
movies['title'].str.extract('.*\((.*)\).*', expand = True).head()
Out[28]:
In [29]:
movies['year'] = movies['title'].str.extract('.*\((.*)\).*', expand = True)
In [30]:
movies.tail()
Out[30]:
In [31]:
'Python Library > Pandas' 카테고리의 다른 글
Day 7. Machine Learning [ Decision Trees ] ( Weather Classification ) (0) | 2019.06.16 |
---|---|
Day 6. Handling Timestamps with Pandas (0) | 2019.06.16 |
Day 6. Frequent operations with pandas -Summary (0) | 2019.06.16 |
Day 6. Frequent operations with pandas - merging (0) | 2019.06.15 |
Day 6. Frequent operations with pandas - aggregation (0) | 2019.06.15 |