In [1]:import pandas as pd import numpy as np In [2]:dow = pd.read_csv("^DJI.csv") In [3]:dow.head() In [4]:type(dow) Out[4]:pandas.core.frame.DataFrame In [5]:dow = pd.read_csv("^DJI.csv", index_col=0) In [6]:dow.head() In [7]:dow.describe() In [8]:dow_open = dow["Open"] In [9]:dow_open.head() Out[9]:Date 2017-01-03 19872.859375 2017-01-04 19890.939453 2017-01-05 19924.560547 2017-01-06 19906.960938 2017-01-09 19931.410156 Name: Open, dtype: float64 In [10]:type(dow_open) Out[10]:pandas.core.series.Series In [11]:dow_high_low = dow[["High", "Low"]] dow_high_low.head() In [12]:dow[dow["High"] > 24000] In [13]:np.random.seed(0) df = pd.DataFrame(np.random.rand(8, 4), columns=["A", "B", "C", "D"]) df In [14]:df.loc[3:5, ["B", "C"]] In [15]:df.iloc[3:5, 1:3] In [16]:df["E"] = df["C"] + df["D"] d In [17]:df["A"] = df["B"] * 2 df In [18]:df.at[1, "A"] = -1 df In [19]:df.iat[2, 0] = -1 df In [20]:df["F"] = [1, None, None, 1, None, None, None, None] df In [21]:df.dropna() In [22]:df.fillna(value=0) In [23]:df In [24]:df.mean() Out [24]:A 0.831787 B 0.669560 C 0.443832 D 0.677766 E 1.121598 F 1.000000 dtype: float64 In [25]:df.std() Out [25]:A 1.170553 B 0.192464 C 0.272506 D 0.283482 E 0.432834 F 0.000000 dtype: float64 In [26]:df.apply(lambda x: x.max() - x.min()) Out [26]:A 2.851193 B 0.542155 C 0.720689 D 0.857540 E 1.490004 F 0.000000 dtype: float64 In [27]:df["G"] = ["X", "X", "Y", "Y", "Z", "X", "Z", "Y"] df In [28]:gr = df.groupby("G") gr.sum() In [29]:gr = df.groupby("G", as_index=False) gr.mean() In [30]:df1 = pd.DataFrame(np.random.rand(3, 3), columns=["A", "B", "C"]) df1 In [31]:df2 = pd.DataFrame(np.random.rand(3, 3), columns=["A", "B", "C"]) df2 In [32]:df3 = pd.concat([df1, df2]) df3 In [33]:df3.reset_index(drop=True) In [34]:df1["D"] = ["A", "B", "D"] df2["D"] = ["A", "B", "C"] In [35]:df1 In [36]:df2 In [37]:pd.merge(df1, df2, on="D") In [38]:pd.merge(df1, df2, how="left", on="D") In [39]:df3.loc[:, ["A", "B", "C"]].values Out [39]:array([[ 0.45615033, 0.56843395, 0.0187898 ], [ 0.6176355 , 0.61209572, 0.616934 ], [ 0.94374808, 0.6818203 , 0.3595079 ], [ 0.43703195, 0.6976312 , 0.06022547], [ 0.66676672, 0.67063787, 0.21038256], [ 0.1289263 , 0.31542835, 0.36371077]])