#subsetting , filtering , insertion, deletion, aggregation
In [2]:
from pandas import *
In [3]:
df = read_csv("./ml/movies.csv", sep = ",")
df.head()
Out[3]:
In [6]:
df[['title', 'genres']].head() # extract specific coulmns
Out[6]:
In [9]:
df[ df['movieId'] > 20 ].head() #filtering out based on conditions
Out[9]:
In [10]:
df['movieId2'] = df['movieId'] + 1 #adding a new column
df.head()
Out[10]:
In [14]:
df.loc[0] = [1, "newRow", "newGenres",None] #replacing first row with new contents
df.head()
Out[14]:
In [19]:
df = df.drop(df.index[[0]]) #drop rows
df.head()
Out[19]:
In [20]:
del df['movieId2'] #delete a column
df.head()
Out[20]:
In [24]:
df['groupName'] = df['movieId'] % 10
df.head()
Out[24]:
In [25]:
df.groupby('groupName').mean()
Out[25]:
In [ ]:
'Python Library > Pandas' 카테고리의 다른 글
Day 6. Frequent operations with pandas - merging (0) | 2019.06.15 |
---|---|
Day 6. Frequent operations with pandas - aggregation (0) | 2019.06.15 |
Day 6. Simple visualization with pandas (0) | 2019.06.15 |
Day 6.Movie Data Analysis Part.2 (0) | 2019.06.15 |
Day 5.Movie Data Analysis Part.1 (0) | 2019.06.13 |