Class03 Answer:

Write NumPy syntax which does something similar to the Pandas syntax below:


"""
class03pd45.py

This script should slice and dice
"""

import pandas as pd
import numpy  as np

prices_df = pd.read_csv('http://ml4.us/csv/GSPC.csv')
prices_df.columns = ['cdate_s','openp','highp','lowp','closep','adjp','volume']

# I should get 2 columns and rows 5 through 11:
s1_df = prices_df[['cdate_s','closep']].iloc[5:11]
print(s1_df)

# I do same as above but in different order.
# I should get rows 5 through 11 and 2 columns:
s2_df = prices_df.iloc[5:11][['cdate_s','closep']]
print(s2_df)
# s1_df and s2_df should have same data.

'bye'

This is easy.


"""
class03pd46.py

This script should slice and dice
"""

import pandas as pd
import numpy  as np

prices_df = pd.read_csv('http://ml4.us/csv/GSPC.csv')

# I should do it the numpy way:
prices_a = np.array(prices_df)
s1_a = prices_a[5:11,[0,4]]
print(s1_a)
# Numpy is more constrained.
# I should specify rows first, columns second.

'bye'

Class03 Lab


ml4.us About Blog Contact Class01 Class02 Class03 Class04 Class05 Class06 Class07 Class08 Class09 Class10 dan101 Forum Google Hangout Vboxen