The Algorithms logo
The Algorithms
À proposFaire un don

Pandas

H
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Pandas.ipynb","version":"0.3.2","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"code","metadata":{"id":"pelSydx1iyH6","colab_type":"code","colab":{}},"source":["import pandas as pd\n","import numpy as np"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"32LqUr1xkqbd","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":235},"outputId":"6a8e5554-cb2c-4f54-aceb-e13c4601d4dd","executionInfo":{"status":"ok","timestamp":1567689598120,"user_tz":-330,"elapsed":936,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["\n","def header(msg):\n","  print('-'*50)\n","  print('['+msg+']')\n","  \n","df = pd.DataFrame(\n","[['Jan',58,42,74,22,2.95],\n","['Feb',61,45,78,26,3.02],\n","['Mar',65,48,84,25,2.34],\n","['Apr',67,50,92,28,1.02],\n","['May',71,53,98,35,0.48],\n","['Jun',75,56,107,41,0.11],\n","['Jul',77,58,105,44,0.0],\n","['Aug',77,59,102,43,0.03],\n","['Sep',77,57,103,40,0.17],\n","['Oct',73,54,96,34,0.81],\n","['Nov',64,48,84,30,1.7],\n","['Dec',58,42,73,21,2.56]],\n","index = [0,1,2,3,4,5,6,7,8,9,10,11],\n","columns = ['month','avg_high','avg_low','record_high','record_low','avg_precipitation'])\n","\n","print(df)\n","df.to_csv('foo.csv')"],"execution_count":3,"outputs":[{"output_type":"stream","text":["   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n","0    Jan        58       42           74          22               2.95\n","1    Feb        61       45           78          26               3.02\n","2    Mar        65       48           84          25               2.34\n","3    Apr        67       50           92          28               1.02\n","4    May        71       53           98          35               0.48\n","5    Jun        75       56          107          41               0.11\n","6    Jul        77       58          105          44               0.00\n","7    Aug        77       59          102          43               0.03\n","8    Sep        77       57          103          40               0.17\n","9    Oct        73       54           96          34               0.81\n","10   Nov        64       48           84          30               1.70\n","11   Dec        58       42           73          21               2.56\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"Icc34VFylFpG","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":286},"outputId":"4179523e-5d04-4c8a-8230-396817bc73d6","executionInfo":{"status":"ok","timestamp":1567689775617,"user_tz":-330,"elapsed":905,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"2.df.head()\")\n","print(df.head())\n","\n","header(\"3.df.tail()\")\n","print(df.head())"],"execution_count":4,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[2.df.head()]\n","  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n","0   Jan        58       42           74          22               2.95\n","1   Feb        61       45           78          26               3.02\n","2   Mar        65       48           84          25               2.34\n","3   Apr        67       50           92          28               1.02\n","4   May        71       53           98          35               0.48\n","--------------------------------------------------\n","[3.df.tail()]\n","  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n","0   Jan        58       42           74          22               2.95\n","1   Feb        61       45           78          26               3.02\n","2   Mar        65       48           84          25               2.34\n","3   Apr        67       50           92          28               1.02\n","4   May        71       53           98          35               0.48\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"afjrWGbMl5Yv","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":181},"outputId":"c6a9a154-041f-40ad-b004-c4d88c2c7f37","executionInfo":{"status":"ok","timestamp":1567690008901,"user_tz":-330,"elapsed":910,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"4.df.dtypes()\")\n","print(df.dtypes)\n","\n"],"execution_count":8,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[4.df.dtypes()]\n","month                 object\n","avg_high               int64\n","avg_low                int64\n","record_high            int64\n","record_low             int64\n","avg_precipitation    float64\n","dtype: object\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"wz3Rjgdnmg3f","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":72},"outputId":"da08654a-2793-4d24-d9fd-c88c696a2251","executionInfo":{"status":"ok","timestamp":1567690026805,"user_tz":-330,"elapsed":990,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"5.df.index()\")\n","print(df.index)\n","\n"],"execution_count":9,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[5.df.index()]\n","Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype='int64')\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"No9z4n2-m2sP","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":108},"outputId":"9e8723b7-e374-4a92-fb4c-292b621df7b1","executionInfo":{"status":"ok","timestamp":1567690033222,"user_tz":-330,"elapsed":883,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"6.df.columns()\")\n","print(df.columns)\n","\n"],"execution_count":10,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[6.df.columns()]\n","Index(['month', 'avg_high', 'avg_low', 'record_high', 'record_low',\n","       'avg_precipitation'],\n","      dtype='object')\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"_RyaclDHm4SP","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":272},"outputId":"589bbfbd-291b-4d5a-94a3-9ec7892756df","executionInfo":{"status":"ok","timestamp":1567690126595,"user_tz":-330,"elapsed":1123,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"7.df.values()\")\n","print(df.values)"],"execution_count":17,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[7.df.values()]\n","[['Jan' 58 42 74 22 2.95]\n"," ['Feb' 61 45 78 26 3.02]\n"," ['Mar' 65 48 84 25 2.34]\n"," ['Apr' 67 50 92 28 1.02]\n"," ['May' 71 53 98 35 0.48]\n"," ['Jun' 75 56 107 41 0.11]\n"," ['Jul' 77 58 105 44 0.0]\n"," ['Aug' 77 59 102 43 0.03]\n"," ['Sep' 77 57 103 40 0.17]\n"," ['Oct' 73 54 96 34 0.81]\n"," ['Nov' 64 48 84 30 1.7]\n"," ['Dec' 58 42 73 21 2.56]]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"b_Q60Dztm5dX","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":325},"outputId":"ba669789-68ad-4e61-d3db-3fe9c6806823","executionInfo":{"status":"ok","timestamp":1567690174226,"user_tz":-330,"elapsed":1085,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"8.df.describe()\")\n","df.describe()"],"execution_count":18,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[8.df.describe()]\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>avg_high</th>\n","      <th>avg_low</th>\n","      <th>record_high</th>\n","      <th>record_low</th>\n","      <th>avg_precipitation</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>count</th>\n","      <td>12.000000</td>\n","      <td>12.000000</td>\n","      <td>12.000000</td>\n","      <td>12.000000</td>\n","      <td>12.000000</td>\n","    </tr>\n","    <tr>\n","      <th>mean</th>\n","      <td>68.583333</td>\n","      <td>51.000000</td>\n","      <td>91.333333</td>\n","      <td>32.416667</td>\n","      <td>1.265833</td>\n","    </tr>\n","    <tr>\n","      <th>std</th>\n","      <td>7.366488</td>\n","      <td>6.060303</td>\n","      <td>12.323911</td>\n","      <td>8.240238</td>\n","      <td>1.186396</td>\n","    </tr>\n","    <tr>\n","      <th>min</th>\n","      <td>58.000000</td>\n","      <td>42.000000</td>\n","      <td>73.000000</td>\n","      <td>21.000000</td>\n","      <td>0.000000</td>\n","    </tr>\n","    <tr>\n","      <th>25%</th>\n","      <td>63.250000</td>\n","      <td>47.250000</td>\n","      <td>82.500000</td>\n","      <td>25.750000</td>\n","      <td>0.155000</td>\n","    </tr>\n","    <tr>\n","      <th>50%</th>\n","      <td>69.000000</td>\n","      <td>51.500000</td>\n","      <td>94.000000</td>\n","      <td>32.000000</td>\n","      <td>0.915000</td>\n","    </tr>\n","    <tr>\n","      <th>75%</th>\n","      <td>75.500000</td>\n","      <td>56.250000</td>\n","      <td>102.250000</td>\n","      <td>40.250000</td>\n","      <td>2.395000</td>\n","    </tr>\n","    <tr>\n","      <th>max</th>\n","      <td>77.000000</td>\n","      <td>59.000000</td>\n","      <td>107.000000</td>\n","      <td>44.000000</td>\n","      <td>3.020000</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["        avg_high    avg_low  record_high  record_low  avg_precipitation\n","count  12.000000  12.000000    12.000000   12.000000          12.000000\n","mean   68.583333  51.000000    91.333333   32.416667           1.265833\n","std     7.366488   6.060303    12.323911    8.240238           1.186396\n","min    58.000000  42.000000    73.000000   21.000000           0.000000\n","25%    63.250000  47.250000    82.500000   25.750000           0.155000\n","50%    69.000000  51.500000    94.000000   32.000000           0.915000\n","75%    75.500000  56.250000   102.250000   40.250000           2.395000\n","max    77.000000  59.000000   107.000000   44.000000           3.020000"]},"metadata":{"tags":[]},"execution_count":18}]},{"cell_type":"code","metadata":{"id":"NZLaZfEOm96I","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":445},"outputId":"55598255-b028-4e89-f8f8-4b84d295e284","executionInfo":{"status":"ok","timestamp":1567690301883,"user_tz":-330,"elapsed":907,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["header(\"8.df.sort_values()\")\n","df.sort_values(\"record_high\" , ascending= \"False\")"],"execution_count":21,"outputs":[{"output_type":"stream","text":["--------------------------------------------------\n","[8.df.sort_values()]\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>month</th>\n","      <th>avg_high</th>\n","      <th>avg_low</th>\n","      <th>record_high</th>\n","      <th>record_low</th>\n","      <th>avg_precipitation</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>11</th>\n","      <td>Dec</td>\n","      <td>58</td>\n","      <td>42</td>\n","      <td>73</td>\n","      <td>21</td>\n","      <td>2.56</td>\n","    </tr>\n","    <tr>\n","      <th>0</th>\n","      <td>Jan</td>\n","      <td>58</td>\n","      <td>42</td>\n","      <td>74</td>\n","      <td>22</td>\n","      <td>2.95</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>Feb</td>\n","      <td>61</td>\n","      <td>45</td>\n","      <td>78</td>\n","      <td>26</td>\n","      <td>3.02</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>Mar</td>\n","      <td>65</td>\n","      <td>48</td>\n","      <td>84</td>\n","      <td>25</td>\n","      <td>2.34</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>Nov</td>\n","      <td>64</td>\n","      <td>48</td>\n","      <td>84</td>\n","      <td>30</td>\n","      <td>1.70</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Apr</td>\n","      <td>67</td>\n","      <td>50</td>\n","      <td>92</td>\n","      <td>28</td>\n","      <td>1.02</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>Oct</td>\n","      <td>73</td>\n","      <td>54</td>\n","      <td>96</td>\n","      <td>34</td>\n","      <td>0.81</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>May</td>\n","      <td>71</td>\n","      <td>53</td>\n","      <td>98</td>\n","      <td>35</td>\n","      <td>0.48</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Aug</td>\n","      <td>77</td>\n","      <td>59</td>\n","      <td>102</td>\n","      <td>43</td>\n","      <td>0.03</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>Sep</td>\n","      <td>77</td>\n","      <td>57</td>\n","      <td>103</td>\n","      <td>40</td>\n","      <td>0.17</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Jul</td>\n","      <td>77</td>\n","      <td>58</td>\n","      <td>105</td>\n","      <td>44</td>\n","      <td>0.00</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>Jun</td>\n","      <td>75</td>\n","      <td>56</td>\n","      <td>107</td>\n","      <td>41</td>\n","      <td>0.11</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n","11   Dec        58       42           73          21               2.56\n","0    Jan        58       42           74          22               2.95\n","1    Feb        61       45           78          26               3.02\n","2    Mar        65       48           84          25               2.34\n","10   Nov        64       48           84          30               1.70\n","3    Apr        67       50           92          28               1.02\n","9    Oct        73       54           96          34               0.81\n","4    May        71       53           98          35               0.48\n","7    Aug        77       59          102          43               0.03\n","8    Sep        77       57          103          40               0.17\n","6    Jul        77       58          105          44               0.00\n","5    Jun        75       56          107          41               0.11"]},"metadata":{"tags":[]},"execution_count":21}]},{"cell_type":"code","metadata":{"id":"h-UR-pZ7n0e3","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":254},"outputId":"dd5dd10e-637d-4465-8f5c-cf3f9a154c42","executionInfo":{"status":"ok","timestamp":1567690323616,"user_tz":-330,"elapsed":908,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df.avg_low"],"execution_count":22,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0     42\n","1     45\n","2     48\n","3     50\n","4     53\n","5     56\n","6     58\n","7     59\n","8     57\n","9     54\n","10    48\n","11    42\n","Name: avg_low, dtype: int64"]},"metadata":{"tags":[]},"execution_count":22}]},{"cell_type":"code","metadata":{"id":"zLZqVMiOn_LX","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":254},"outputId":"9b988375-5e66-46c9-8b91-579203481bca","executionInfo":{"status":"ok","timestamp":1567690362691,"user_tz":-330,"elapsed":893,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df['avg_low']"],"execution_count":23,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0     42\n","1     45\n","2     48\n","3     50\n","4     53\n","5     56\n","6     58\n","7     59\n","8     57\n","9     54\n","10    48\n","11    42\n","Name: avg_low, dtype: int64"]},"metadata":{"tags":[]},"execution_count":23}]},{"cell_type":"code","metadata":{"id":"k-j6WJQAoIuH","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":108},"outputId":"f421f09e-11e8-4be1-a623-6a888132bb0d","executionInfo":{"status":"ok","timestamp":1567690375485,"user_tz":-330,"elapsed":902,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df[2:4]"],"execution_count":24,"outputs":[{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>month</th>\n","      <th>avg_high</th>\n","      <th>avg_low</th>\n","      <th>record_high</th>\n","      <th>record_low</th>\n","      <th>avg_precipitation</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>2</th>\n","      <td>Mar</td>\n","      <td>65</td>\n","      <td>48</td>\n","      <td>84</td>\n","      <td>25</td>\n","      <td>2.34</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>Apr</td>\n","      <td>67</td>\n","      <td>50</td>\n","      <td>92</td>\n","      <td>28</td>\n","      <td>1.02</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n","2   Mar        65       48           84          25               2.34\n","3   Apr        67       50           92          28               1.02"]},"metadata":{"tags":[]},"execution_count":24}]},{"cell_type":"code","metadata":{"id":"kq7wKhXZoL13","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":408},"outputId":"94b59318-0ef7-48d1-c2d8-75e3a2d72c50","executionInfo":{"status":"ok","timestamp":1567690428125,"user_tz":-330,"elapsed":892,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df[['avg_low','avg_high','record_high']]"],"execution_count":25,"outputs":[{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>avg_low</th>\n","      <th>avg_high</th>\n","      <th>record_high</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>42</td>\n","      <td>58</td>\n","      <td>74</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>45</td>\n","      <td>61</td>\n","      <td>78</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>48</td>\n","      <td>65</td>\n","      <td>84</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>50</td>\n","      <td>67</td>\n","      <td>92</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>53</td>\n","      <td>71</td>\n","      <td>98</td>\n","    </tr>\n","    <tr>\n","      <th>5</th>\n","      <td>56</td>\n","      <td>75</td>\n","      <td>107</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>58</td>\n","      <td>77</td>\n","      <td>105</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>59</td>\n","      <td>77</td>\n","      <td>102</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>57</td>\n","      <td>77</td>\n","      <td>103</td>\n","    </tr>\n","    <tr>\n","      <th>9</th>\n","      <td>54</td>\n","      <td>73</td>\n","      <td>96</td>\n","    </tr>\n","    <tr>\n","      <th>10</th>\n","      <td>48</td>\n","      <td>64</td>\n","      <td>84</td>\n","    </tr>\n","    <tr>\n","      <th>11</th>\n","      <td>42</td>\n","      <td>58</td>\n","      <td>73</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["    avg_low  avg_high  record_high\n","0        42        58           74\n","1        45        61           78\n","2        48        65           84\n","3        50        67           92\n","4        53        71           98\n","5        56        75          107\n","6        58        77          105\n","7        59        77          102\n","8        57        77          103\n","9        54        73           96\n","10       48        64           84\n","11       42        58           73"]},"metadata":{"tags":[]},"execution_count":25}]},{"cell_type":"code","metadata":{"id":"lef2QUvipHBw","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":138},"outputId":"539af8bc-90bb-4c0b-9975-3cf47ef0faec","executionInfo":{"status":"ok","timestamp":1567690651829,"user_tz":-330,"elapsed":958,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df.iloc[5:8 , [0,3]]  #it will use as array "],"execution_count":31,"outputs":[{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>month</th>\n","      <th>record_high</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>5</th>\n","      <td>Jun</td>\n","      <td>107</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>Jul</td>\n","      <td>105</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>Aug</td>\n","      <td>102</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  month  record_high\n","5   Jun          107\n","6   Jul          105\n","7   Aug          102"]},"metadata":{"tags":[]},"execution_count":31}]},{"cell_type":"code","metadata":{"id":"4si2C3eEoYsf","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":168},"outputId":"9900474e-f147-43a6-a167-6b972b9ccea2","executionInfo":{"status":"ok","timestamp":1567690473497,"user_tz":-330,"elapsed":1099,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df.loc[5:8 , ['avg_low','avg_high','record_high']]"],"execution_count":26,"outputs":[{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>avg_low</th>\n","      <th>avg_high</th>\n","      <th>record_high</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>5</th>\n","      <td>56</td>\n","      <td>75</td>\n","      <td>107</td>\n","    </tr>\n","    <tr>\n","      <th>6</th>\n","      <td>58</td>\n","      <td>77</td>\n","      <td>105</td>\n","    </tr>\n","    <tr>\n","      <th>7</th>\n","      <td>59</td>\n","      <td>77</td>\n","      <td>102</td>\n","    </tr>\n","    <tr>\n","      <th>8</th>\n","      <td>57</td>\n","      <td>77</td>\n","      <td>103</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["   avg_low  avg_high  record_high\n","5       56        75          107\n","6       58        77          105\n","7       59        77          102\n","8       57        77          103"]},"metadata":{"tags":[]},"execution_count":26}]},{"cell_type":"code","metadata":{"id":"SUewro9tojuP","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":90},"outputId":"c695ca48-1bd1-4a83-9a52-817af2b7f59f","executionInfo":{"status":"ok","timestamp":1567690492152,"user_tz":-330,"elapsed":899,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df.loc[9, ['avg_low','avg_high','record_high']]"],"execution_count":27,"outputs":[{"output_type":"execute_result","data":{"text/plain":["avg_low        54\n","avg_high       73\n","record_high    96\n","Name: 9, dtype: object"]},"metadata":{"tags":[]},"execution_count":27}]},{"cell_type":"code","metadata":{"id":"rZYQ0Z9_ooUv","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":108},"outputId":"8d4f91ee-adb6-4b37-cb85-ac39532fa11f","executionInfo":{"status":"ok","timestamp":1567690530488,"user_tz":-330,"elapsed":1324,"user":{"displayName":"HRITIK JAISWAL","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mAIoT5asTvy-RaZPvDKRvz2bMxFBhU-1QvQZ2E4=s64","userId":"10596177819840519504"}}},"source":["df.iloc[3:5,[0,3]]"],"execution_count":28,"outputs":[{"output_type":"execute_result","data":{"text/html":["<div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>month</th>\n","      <th>record_high</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>3</th>\n","      <td>Apr</td>\n","      <td>92</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>May</td>\n","      <td>98</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>"],"text/plain":["  month  record_high\n","3   Apr           92\n","4   May           98"]},"metadata":{"tags":[]},"execution_count":28}]},{"cell_type":"code","metadata":{"id":"FFsOEqRioxlP","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]}
À propos de cet Algorithme
import pandas as pd
import numpy as np

def header(msg):
  print('-'*50)
  print('['+msg+']')
  
df = pd.DataFrame(
[['Jan',58,42,74,22,2.95],
['Feb',61,45,78,26,3.02],
['Mar',65,48,84,25,2.34],
['Apr',67,50,92,28,1.02],
['May',71,53,98,35,0.48],
['Jun',75,56,107,41,0.11],
['Jul',77,58,105,44,0.0],
['Aug',77,59,102,43,0.03],
['Sep',77,57,103,40,0.17],
['Oct',73,54,96,34,0.81],
['Nov',64,48,84,30,1.7],
['Dec',58,42,73,21,2.56]],
index = [0,1,2,3,4,5,6,7,8,9,10,11],
columns = ['month','avg_high','avg_low','record_high','record_low','avg_precipitation'])

print(df)
df.to_csv('foo.csv')
   month  avg_high  avg_low  record_high  record_low  avg_precipitation
0    Jan        58       42           74          22               2.95
1    Feb        61       45           78          26               3.02
2    Mar        65       48           84          25               2.34
3    Apr        67       50           92          28               1.02
4    May        71       53           98          35               0.48
5    Jun        75       56          107          41               0.11
6    Jul        77       58          105          44               0.00
7    Aug        77       59          102          43               0.03
8    Sep        77       57          103          40               0.17
9    Oct        73       54           96          34               0.81
10   Nov        64       48           84          30               1.70
11   Dec        58       42           73          21               2.56
header("2.df.head()")
print(df.head())

header("3.df.tail()")
print(df.head())
--------------------------------------------------
[2.df.head()]
  month  avg_high  avg_low  record_high  record_low  avg_precipitation
0   Jan        58       42           74          22               2.95
1   Feb        61       45           78          26               3.02
2   Mar        65       48           84          25               2.34
3   Apr        67       50           92          28               1.02
4   May        71       53           98          35               0.48
--------------------------------------------------
[3.df.tail()]
  month  avg_high  avg_low  record_high  record_low  avg_precipitation
0   Jan        58       42           74          22               2.95
1   Feb        61       45           78          26               3.02
2   Mar        65       48           84          25               2.34
3   Apr        67       50           92          28               1.02
4   May        71       53           98          35               0.48
header("4.df.dtypes()")
print(df.dtypes)

--------------------------------------------------
[4.df.dtypes()]
month                 object
avg_high               int64
avg_low                int64
record_high            int64
record_low             int64
avg_precipitation    float64
dtype: object
header("5.df.index()")
print(df.index)

--------------------------------------------------
[5.df.index()]
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype=&#x27;int64&#x27;)
header("6.df.columns()")
print(df.columns)

--------------------------------------------------
[6.df.columns()]
Index([&#x27;month&#x27;, &#x27;avg_high&#x27;, &#x27;avg_low&#x27;, &#x27;record_high&#x27;, &#x27;record_low&#x27;,
       &#x27;avg_precipitation&#x27;],
      dtype=&#x27;object&#x27;)
header("7.df.values()")
print(df.values)
--------------------------------------------------
[7.df.values()]
[[&#x27;Jan&#x27; 58 42 74 22 2.95]
 [&#x27;Feb&#x27; 61 45 78 26 3.02]
 [&#x27;Mar&#x27; 65 48 84 25 2.34]
 [&#x27;Apr&#x27; 67 50 92 28 1.02]
 [&#x27;May&#x27; 71 53 98 35 0.48]
 [&#x27;Jun&#x27; 75 56 107 41 0.11]
 [&#x27;Jul&#x27; 77 58 105 44 0.0]
 [&#x27;Aug&#x27; 77 59 102 43 0.03]
 [&#x27;Sep&#x27; 77 57 103 40 0.17]
 [&#x27;Oct&#x27; 73 54 96 34 0.81]
 [&#x27;Nov&#x27; 64 48 84 30 1.7]
 [&#x27;Dec&#x27; 58 42 73 21 2.56]]
header("8.df.describe()")
df.describe()
--------------------------------------------------
[8.df.describe()]
avg_high avg_low record_high record_low avg_precipitation
count 12.000000 12.000000 12.000000 12.000000 12.000000
mean 68.583333 51.000000 91.333333 32.416667 1.265833
std 7.366488 6.060303 12.323911 8.240238 1.186396
min 58.000000 42.000000 73.000000 21.000000 0.000000
25% 63.250000 47.250000 82.500000 25.750000 0.155000
50% 69.000000 51.500000 94.000000 32.000000 0.915000
75% 75.500000 56.250000 102.250000 40.250000 2.395000
max 77.000000 59.000000 107.000000 44.000000 3.020000
header("8.df.sort_values()")
df.sort_values("record_high" , ascending= "False")
--------------------------------------------------
[8.df.sort_values()]
month avg_high avg_low record_high record_low avg_precipitation
11 Dec 58 42 73 21 2.56
0 Jan 58 42 74 22 2.95
1 Feb 61 45 78 26 3.02
2 Mar 65 48 84 25 2.34
10 Nov 64 48 84 30 1.70
3 Apr 67 50 92 28 1.02
9 Oct 73 54 96 34 0.81
4 May 71 53 98 35 0.48
7 Aug 77 59 102 43 0.03
8 Sep 77 57 103 40 0.17
6 Jul 77 58 105 44 0.00
5 Jun 75 56 107 41 0.11
df.avg_low
0     42
1     45
2     48
3     50
4     53
5     56
6     58
7     59
8     57
9     54
10    48
11    42
Name: avg_low, dtype: int64
df['avg_low']
0     42
1     45
2     48
3     50
4     53
5     56
6     58
7     59
8     57
9     54
10    48
11    42
Name: avg_low, dtype: int64
df[2:4]
month avg_high avg_low record_high record_low avg_precipitation
2 Mar 65 48 84 25 2.34
3 Apr 67 50 92 28 1.02
df[['avg_low','avg_high','record_high']]
avg_low avg_high record_high
0 42 58 74
1 45 61 78
2 48 65 84
3 50 67 92
4 53 71 98
5 56 75 107
6 58 77 105
7 59 77 102
8 57 77 103
9 54 73 96
10 48 64 84
11 42 58 73
df.iloc[5:8 , [0,3]]  #it will use as array 
month record_high
5 Jun 107
6 Jul 105
7 Aug 102
df.loc[5:8 , ['avg_low','avg_high','record_high']]
avg_low avg_high record_high
5 56 75 107
6 58 77 105
7 59 77 102
8 57 77 103
df.loc[9, ['avg_low','avg_high','record_high']]
avg_low        54
avg_high       73
record_high    96
Name: 9, dtype: object
df.iloc[3:5,[0,3]]
month record_high
3 Apr 92
4 May 98