import pandas as pd
d = { '_key' : pd.Series(['K0', 'K1','K2','K3']),
'_key2' : pd.Series(['z0', 'z1','z2','z3']),
'hire_date' : pd.Series(['h0', 'h1','h2','h3']),
'professtion' : pd.Series(['p0', 'p1','p2','p3']) }
d
Out[6]:
In [8]:
df_right = pd.DataFrame(d)
df_right
Out[8]:
In [9]:
d = { '_key' : pd.Series(['K0', 'K1','K2','K3']),
'_key2' : pd.Series(['z0', 'z1','z2','z3']),
'city' : pd.Series(['c0', 'c1','c2','c3']),
'user_name': pd.Series(['u0', 'u1','u2','u3']) }
df_left = pd.DataFrame(d)
df_left
Out[9]:
In [11]:
pd.concat([df_left, df_left]) # merge rows of two dataframe
Out[11]:
In [12]:
pd.concat([df_left, df_right])
Out[12]:
In [13]:
pd.concat([df_left, df_right], axis = 1, join = 'inner')
Out[13]:
In [15]:
pd.merge(df_left, df_right, how = 'inner')
Out[15]:
In [16]:
df_left.append(df_right)
Out[16]:
In [18]:
tags = pd.read_csv("./ml/tags.csv" )
movies = pd.read_csv("./ml/movies.csv")
In [20]:
tags.head()
Out[20]:
In [21]:
movies.head()
Out[21]:
In [22]:
t = movies.merge(tags, on = "movieId", how = 'inner')
t.head()
Out[22]:
In [23]:
del t['timestamp']
In [24]:
t.head()
Out[24]:
In [ ]:
'Python Library > Pandas' 카테고리의 다른 글
Day 6. String Operations with Pandas (0) | 2019.06.16 |
---|---|
Day 6. Frequent operations with pandas -Summary (0) | 2019.06.16 |
Day 6. Frequent operations with pandas - aggregation (0) | 2019.06.15 |
Day 6. Frequent operations with pandas - subsetting, filtering, delegation (0) | 2019.06.15 |
Day 6. Simple visualization with pandas (0) | 2019.06.15 |