{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4b1c158e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr = np.array([1,2,3])\n",
    "arr.ndim\n",
    "arr.shape\n",
    "arr.reshape(8)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dea737b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0        Python\n",
      "1             C\n",
      "2          Java\n",
      "3    JavaScript\n",
      "4           PHP\n",
      "5             R\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 传入列表创建Series，使用默认0~n的数字索引\n",
    "ser_obj = pd.Series(data=['Python', 'C', 'Java', 'JavaScript', 'PHP', 'R'])\n",
    "print(ser_obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a38edcd7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a        Python\n",
      "b             C\n",
      "c          Java\n",
      "d    JavaScript\n",
      "e           PHP\n",
      "f             R\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 传入data和index参数，自定义标签索引\n",
    "ser_obj = pd.Series(\n",
    "    data=['Python', 'C', 'Java', 'JavaScript', 'PHP', 'R'],\n",
    "    index=['a', 'b', 'c', 'd', 'e', 'f']\n",
    ")\n",
    "print(ser_obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5bdcc06b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    0   1   2   3   4\n",
      "0   1   2   3   4   5\n",
      "1   6   7   8   9  10\n",
      "2  11  12  13  14  15\n",
      "3  16  17  18  19  20\n",
      "4  21  22  23  24  25\n",
      "5  26  27  28  29  30\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# 生成1~30的一维数组，并重塑为6行5列的二维数组\n",
    "arr_2d = np.arange(1, 31).reshape((6, 5))\n",
    "\n",
    "# 将二维数组转换为DataFrame\n",
    "df_obj = pd.DataFrame(data=arr_2d)\n",
    "\n",
    "# 打印DataFrame\n",
    "print(df_obj)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7f1b267e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   No1  No2  No3  No4  No5\n",
      "0    1    2    3    4    5\n",
      "1    6    7    8    9   10\n",
      "2   11   12   13   14   15\n",
      "3   16   17   18   19   20\n",
      "4   21   22   23   24   25\n",
      "5   26   27   28   29   30\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0     2\n",
       "1     7\n",
       "2    12\n",
       "3    17\n",
       "4    22\n",
       "5    27\n",
       "Name: No2, dtype: int32"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# 生成1~30的一维数组，并重塑为6行5列的二维数组\n",
    "arr_2d = np.arange(1, 31).reshape((6, 5))\n",
    "\n",
    "# 创建DataFrame并自定义列名\n",
    "df_obj = pd.DataFrame(\n",
    "    data=arr_2d,\n",
    "    columns=['No1', 'No2', 'No3', 'No4', 'No5']\n",
    ")\n",
    "\n",
    "# 打印DataFrame\n",
    "print(df_obj)\n",
    "result =  df_obj.No2\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5bf3cce3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=6, step=1)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_obj.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6748b92e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['No1', 'No2', 'No3', 'No4', 'No5'], dtype='object')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_obj.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "2c0fd53c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4,  5],\n",
       "       [ 6,  7,  8,  9, 10],\n",
       "       [11, 12, 13, 14, 15],\n",
       "       [16, 17, 18, 19, 20],\n",
       "       [21, 22, 23, 24, 25],\n",
       "       [26, 27, 28, 29, 30]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_obj.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70906ca6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
