import pandas as pd
import numpy as np

starting_date = '20160701'
sample_numpy_data = np.array(np.arange(24)).reshape((6,4))
dates_index = pd.date_range(starting_date, periods=6)
sample_df = pd.DataFrame(sample_numpy_data, index=dates_index, columns=list('ABCD'))

sample_df_2 = sample_df.copy()
sample_df_2['Fruits'] = ['apple', 'orange','banana','strawberry','blueberry','pineapple']

sample_series = pd.Series([1,2,3,4,5,6], index=pd.date_range(starting_date, periods=6))
sample_df_2['Extra Data'] = sample_series *3 +1

second_numpy_array = np.array(np.arange(len(sample_df_2)))  *100 + 7
sample_df_2['G'] = second_numpy_array

sample_df_2

"""
Explanation: Merge

Concat 
Join   
Append
End of explanation
"""


pieces = [sample_df_2[:2], sample_df_2[2:4], sample_df_2[4:]]
pieces

"""
Explanation: concat()
documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html
separate data frame into a list with 3 elements
End of explanation
"""


new_list = pieces[0], pieces[2]
pd.concat(new_list)

"""
Explanation: concatenate first and last elements
End of explanation
"""


new_last_row = sample_df_2.iloc[2]

sample_df_2.append(new_last_row)

sample_df_2

"""
Explanation: append()
documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.append.html
End of explanation
"""


left = pd.DataFrame({'my_key': ['K0', 'K1', 'K2', 'K3'],
 'A': ['A0', 'A1', 'A2', 'A3'],
 'B': ['B0', 'B1', 'B2', 'B3']})
right = pd.DataFrame({'my_key': ['K0', 'K1', 'K2', 'K3'],
 'C': ['C0', 'C1', 'C2', 'C3'],
 'D': ['D0', 'D1', 'D2', 'D3']})

result = pd.merge(left, right, on='my_key')
result

"""
Explanation: merge()
documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html
Merge DataFrame objects by performing a database-style join operation by columns or indexes.
If joining columns on columns, the DataFrame indexes will be ignored. Otherwise if joining indexes on indexes or indexes on a column or columns, the index will be passed on.
End of explanation
"""


