import pandas as pdpd.Series(['Alice', 'Jack', 'Molly'])pd.Series([1, 2, 3])pd.Series(['Alice', 'Jack', None])pd.Series([1, 2, None])students_scores = {'Alice': 'Physics', 'Jack': 'Chemistry', 'Molly': 'English'}s = pd.Series(students_scores)s = pd.Series(['Physics', 'Chemistry', 'English'], index=['Alice', 'Jack', 'Molly'])# iloc 은 Index 순서를 기준s.iloc[3]s[3]# loc 은 지정된 Index 를 기준s.loc['Molly']class_code = {99: 'Physics', 100: 'Chemistry', 101: 'English', 102: 'History'}s = pd.Series(class_code)# 숫자를 Index 로 지정할 경우 iloc 은 에러s[0]# NumPy 는 내부적으로 병렬처리가 구현되어있기 때문에 단순한 iteration 보다 훨씬 빠른 성능을 가진다s = pd.Series(np.random.randint(0,1000,1000))np.sum(s)s+=2
import matplotlib.pyplot as pltimport numpy as npx = np.array([1,2,3,4,5,6,7,8])y = xplt.figure()plt.scatter(x[:2], y[:2], s=100, c='red', label='Tall students')plt.scatter(x[2:], y[2:], s=100, c='blue', label='Short students')plt.xlabel('The number of times the child kicked a ball')plt.ylabel('The grade of the student')plt.title('Relationship between ball kicking and grades')plt.legend(loc=4, frameon=False, title='Legend')
Line Plots
import matplotlib.pyplot as pltimport numpy as nplinear_data = np.array([1,2,3,4,5,6,7,8])exponential_data = linear_data**2plt.figure(figsize=(8,6))observation_dates = np.arange('2017-01-01', '2017-01-09', dtype='datetime64[D]')plt.plot(observation_dates, linear_data, '-o', observation_dates, exponential_data, '-o')plt.gca().fill_between(range(len(linear_data)), linear_data, exponential_data, facecolor='blue', alpha=0.25)x = plt.gca().xaxisfor item in x.get_ticklabels(): item.set_rotation(45)ax = plt.gca()ax.set_xlabel('Date')ax.set_ylabel('Units')ax.set_title("Exponential ($x^2$) vs. Linear ($x$) performance")