4
4
"metadata" : {
5
5
"colab" : {
6
6
"provenance" : [],
7
- "authorship_tag" : " ABX9TyP6CLE4Aseaf5bHq6gItZ+K " ,
7
+ "authorship_tag" : " ABX9TyNspALEWfspOU4EISKEpAa1 " ,
8
8
"include_colab_link" : true
9
9
},
10
10
"kernelspec" : {
28
28
},
29
29
{
30
30
"cell_type" : " code" ,
31
- "execution_count" : null ,
31
+ "execution_count" : 4 ,
32
32
"metadata" : {
33
33
"colab" : {
34
34
"base_uri" : " https://localhost:8080/"
35
35
},
36
36
"id" : " 2T2yFd5ebn4K" ,
37
- "outputId" : " e9b9474d-6457-430d-b01d-1022948e2e85 "
37
+ "outputId" : " ac75d61b-e9f8-4363-e0ff-232592ef37ea "
38
38
},
39
39
"outputs" : [
40
40
{
64
64
" df_all.info()"
65
65
]
66
66
},
67
+ {
68
+ "cell_type" : " code" ,
69
+ "source" : [
70
+ " df.isna"
71
+ ],
72
+ "metadata" : {
73
+ "colab" : {
74
+ "base_uri" : " https://localhost:8080/"
75
+ },
76
+ "id" : " -m8AsyshVFZ5" ,
77
+ "outputId" : " 7f27a6b0-8d9a-42ef-ef12-0a5804f6abaa"
78
+ },
79
+ "execution_count" : 13 ,
80
+ "outputs" : [
81
+ {
82
+ "output_type" : " execute_result" ,
83
+ "data" : {
84
+ "text/plain" : [
85
+ " <bound method DataFrame.isna of Column1 Column2 Column3\n " ,
86
+ " 0 10 0 1st\n " ,
87
+ " 1 25 NULL 3rd\n " ,
88
+ " 2 NULL 1 3rd\n " ,
89
+ " 3 70 0 2nd\n " ,
90
+ " 4 18 1 1st>"
91
+ ]
92
+ },
93
+ "metadata" : {},
94
+ "execution_count" : 13
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "cell_type" : " code" ,
100
+ "source" : [
101
+ " # Find columns with NaN values\n " ,
102
+ " columns_with_nan = df.columns[df.isna().any()].tolist()\n " ,
103
+ " \n " ,
104
+ " # Print the column names\n " ,
105
+ " print(', '.join(columns_with_nan))"
106
+ ],
107
+ "metadata" : {
108
+ "colab" : {
109
+ "base_uri" : " https://localhost:8080/"
110
+ },
111
+ "id" : " MaIfl98vaK5U" ,
112
+ "outputId" : " d10e9982-4e94-446c-cb60-950f45519396"
113
+ },
114
+ "execution_count" : 15 ,
115
+ "outputs" : [
116
+ {
117
+ "output_type" : " stream" ,
118
+ "name" : " stdout" ,
119
+ "text" : [
120
+ " \n "
121
+ ]
122
+ }
123
+ ]
124
+ },
67
125
{
68
126
"cell_type" : " code" ,
69
127
"source" : [
731
789
},
732
790
{
733
791
"cell_type" : " code" ,
734
- "source" : [],
792
+ "source" : [
793
+ " df.drop({'Column1','Column2'}, axis=1)"
794
+ ],
735
795
"metadata" : {
736
- "id" : " gpX1wsiUBdVN"
796
+ "colab" : {
797
+ "base_uri" : " https://localhost:8080/" ,
798
+ "height" : 206
799
+ },
800
+ "id" : " gpX1wsiUBdVN" ,
801
+ "outputId" : " 38586426-b0ad-447b-995f-7a75da743bab"
737
802
},
738
- "execution_count" : null ,
739
- "outputs" : []
803
+ "execution_count" : 3 ,
804
+ "outputs" : [
805
+ {
806
+ "output_type" : " execute_result" ,
807
+ "data" : {
808
+ "text/plain" : [
809
+ " Column3\n " ,
810
+ " 0 1st\n " ,
811
+ " 1 3rd\n " ,
812
+ " 2 3rd\n " ,
813
+ " 3 2nd\n " ,
814
+ " 4 1st"
815
+ ],
816
+ "text/html" : [
817
+ " \n " ,
818
+ " <div id=\" df-787fd3a7-4838-4e96-a920-e37ad624d125\" >\n " ,
819
+ " <div class=\" colab-df-container\" >\n " ,
820
+ " <div>\n " ,
821
+ " <style scoped>\n " ,
822
+ " .dataframe tbody tr th:only-of-type {\n " ,
823
+ " vertical-align: middle;\n " ,
824
+ " }\n " ,
825
+ " \n " ,
826
+ " .dataframe tbody tr th {\n " ,
827
+ " vertical-align: top;\n " ,
828
+ " }\n " ,
829
+ " \n " ,
830
+ " .dataframe thead th {\n " ,
831
+ " text-align: right;\n " ,
832
+ " }\n " ,
833
+ " </style>\n " ,
834
+ " <table border=\" 1\" class=\" dataframe\" >\n " ,
835
+ " <thead>\n " ,
836
+ " <tr style=\" text-align: right;\" >\n " ,
837
+ " <th></th>\n " ,
838
+ " <th>Column3</th>\n " ,
839
+ " </tr>\n " ,
840
+ " </thead>\n " ,
841
+ " <tbody>\n " ,
842
+ " <tr>\n " ,
843
+ " <th>0</th>\n " ,
844
+ " <td>1st</td>\n " ,
845
+ " </tr>\n " ,
846
+ " <tr>\n " ,
847
+ " <th>1</th>\n " ,
848
+ " <td>3rd</td>\n " ,
849
+ " </tr>\n " ,
850
+ " <tr>\n " ,
851
+ " <th>2</th>\n " ,
852
+ " <td>3rd</td>\n " ,
853
+ " </tr>\n " ,
854
+ " <tr>\n " ,
855
+ " <th>3</th>\n " ,
856
+ " <td>2nd</td>\n " ,
857
+ " </tr>\n " ,
858
+ " <tr>\n " ,
859
+ " <th>4</th>\n " ,
860
+ " <td>1st</td>\n " ,
861
+ " </tr>\n " ,
862
+ " </tbody>\n " ,
863
+ " </table>\n " ,
864
+ " </div>\n " ,
865
+ " <button class=\" colab-df-convert\" onclick=\" convertToInteractive('df-787fd3a7-4838-4e96-a920-e37ad624d125')\"\n " ,
866
+ " title=\" Convert this dataframe to an interactive table.\"\n " ,
867
+ " style=\" display:none;\" >\n " ,
868
+ " \n " ,
869
+ " <svg xmlns=\" http://www.w3.org/2000/svg\" height=\" 24px\" viewBox=\" 0 0 24 24\"\n " ,
870
+ " width=\" 24px\" >\n " ,
871
+ " <path d=\" M0 0h24v24H0V0z\" fill=\" none\" />\n " ,
872
+ " <path d=\" M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\" /><path d=\" M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\" />\n " ,
873
+ " </svg>\n " ,
874
+ " </button>\n " ,
875
+ " \n " ,
876
+ " <style>\n " ,
877
+ " .colab-df-container {\n " ,
878
+ " display:flex;\n " ,
879
+ " flex-wrap:wrap;\n " ,
880
+ " gap: 12px;\n " ,
881
+ " }\n " ,
882
+ " \n " ,
883
+ " .colab-df-convert {\n " ,
884
+ " background-color: #E8F0FE;\n " ,
885
+ " border: none;\n " ,
886
+ " border-radius: 50%;\n " ,
887
+ " cursor: pointer;\n " ,
888
+ " display: none;\n " ,
889
+ " fill: #1967D2;\n " ,
890
+ " height: 32px;\n " ,
891
+ " padding: 0 0 0 0;\n " ,
892
+ " width: 32px;\n " ,
893
+ " }\n " ,
894
+ " \n " ,
895
+ " .colab-df-convert:hover {\n " ,
896
+ " background-color: #E2EBFA;\n " ,
897
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n " ,
898
+ " fill: #174EA6;\n " ,
899
+ " }\n " ,
900
+ " \n " ,
901
+ " [theme=dark] .colab-df-convert {\n " ,
902
+ " background-color: #3B4455;\n " ,
903
+ " fill: #D2E3FC;\n " ,
904
+ " }\n " ,
905
+ " \n " ,
906
+ " [theme=dark] .colab-df-convert:hover {\n " ,
907
+ " background-color: #434B5C;\n " ,
908
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n " ,
909
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n " ,
910
+ " fill: #FFFFFF;\n " ,
911
+ " }\n " ,
912
+ " </style>\n " ,
913
+ " \n " ,
914
+ " <script>\n " ,
915
+ " const buttonEl =\n " ,
916
+ " document.querySelector('#df-787fd3a7-4838-4e96-a920-e37ad624d125 button.colab-df-convert');\n " ,
917
+ " buttonEl.style.display =\n " ,
918
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n " ,
919
+ " \n " ,
920
+ " async function convertToInteractive(key) {\n " ,
921
+ " const element = document.querySelector('#df-787fd3a7-4838-4e96-a920-e37ad624d125');\n " ,
922
+ " const dataTable =\n " ,
923
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n " ,
924
+ " [key], {});\n " ,
925
+ " if (!dataTable) return;\n " ,
926
+ " \n " ,
927
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n " ,
928
+ " '<a target=\" _blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n " ,
929
+ " + ' to learn more about interactive tables.';\n " ,
930
+ " element.innerHTML = '';\n " ,
931
+ " dataTable['output_type'] = 'display_data';\n " ,
932
+ " await google.colab.output.renderOutput(dataTable, element);\n " ,
933
+ " const docLink = document.createElement('div');\n " ,
934
+ " docLink.innerHTML = docLinkHtml;\n " ,
935
+ " element.appendChild(docLink);\n " ,
936
+ " }\n " ,
937
+ " </script>\n " ,
938
+ " </div>\n " ,
939
+ " </div>\n " ,
940
+ " "
941
+ ]
942
+ },
943
+ "metadata" : {},
944
+ "execution_count" : 3
945
+ }
946
+ ]
947
+ },
948
+ {
949
+ "cell_type" : " code" ,
950
+ "source" : [
951
+ " import pandas as pd\n " ,
952
+ " data = pd.read_csv('/content/task4_1_939291.csv')\n " ,
953
+ " data.info()"
954
+ ],
955
+ "metadata" : {
956
+ "colab" : {
957
+ "base_uri" : " https://localhost:8080/"
958
+ },
959
+ "id" : " 4fAtb7IUif1J" ,
960
+ "outputId" : " ab33d3c2-6530-4cc0-9783-d00520d746a2"
961
+ },
962
+ "execution_count" : 23 ,
963
+ "outputs" : [
964
+ {
965
+ "output_type" : " stream" ,
966
+ "name" : " stdout" ,
967
+ "text" : [
968
+ " <class 'pandas.core.frame.DataFrame'>\n " ,
969
+ " RangeIndex: 200 entries, 0 to 199\n " ,
970
+ " Data columns (total 6 columns):\n " ,
971
+ " # Column Non-Null Count Dtype\n " ,
972
+ " --- ------ -------------- -----\n " ,
973
+ " 0 ID 200 non-null int64\n " ,
974
+ " 1 DISTANCE 200 non-null int64\n " ,
975
+ " 2 STOP_COUNT 200 non-null int64\n " ,
976
+ " 3 COST 200 non-null int64\n " ,
977
+ " 4 FITNESS 200 non-null int64\n " ,
978
+ " 5 INTERNET 200 non-null int64\n " ,
979
+ " dtypes: int64(6)\n " ,
980
+ " memory usage: 9.5 KB\n "
981
+ ]
982
+ }
983
+ ]
984
+ },
985
+ {
986
+ "cell_type" : " code" ,
987
+ "source" : [
988
+ " import pandas as pd\n " ,
989
+ " \n " ,
990
+ " # Присвоение имен столбцам\n " ,
991
+ " data.columns = ['ID', 'Расстояние до метро (мин)', 'Количество остановок на метро', 'Стоимость аренды', 'Расстояние до фитнес-клуба (мин)', 'Количество интернет-провайдеров']\n " ,
992
+ " \n " ,
993
+ " # Экспоненциальная нормировка\n " ,
994
+ " normalized_distance = data['Расстояние до метро (мин)'].apply(lambda x: 1 / (2 ** x))\n " ,
995
+ " normalized_stops = data['Количество остановок на метро'].apply(lambda x: 1 / (2 ** x))\n " ,
996
+ " normalized_rent = data['Стоимость аренды'].apply(lambda x: 1 / x)\n " ,
997
+ " normalized_fitness = data['Расстояние до фитнес-клуба (мин)'].apply(lambda x: 1 / (2 ** x))\n " ,
998
+ " normalized_providers = -0.4 * data['Количество интернет-провайдеров']\n " ,
999
+ " \n " ,
1000
+ " # Вычисление целевой функции\n " ,
1001
+ " target_function = normalized_distance + normalized_stops + normalized_rent + 0.2 * normalized_fitness + normalized_providers\n " ,
1002
+ " \n " ,
1003
+ " # Выбор трех лучших вариантов\n " ,
1004
+ " best_options = target_function.nsmallest(3)\n " ,
1005
+ " \n " ,
1006
+ " # Получение идентификаторов трех лучших вариантов\n " ,
1007
+ " best_ids = best_options.index.tolist()\n " ,
1008
+ " \n " ,
1009
+ " # Вывод результатов\n " ,
1010
+ " print('Идентификаторы трех лучших вариантов:', ', '.join(map(str, best_ids)))\n "
1011
+ ],
1012
+ "metadata" : {
1013
+ "colab" : {
1014
+ "base_uri" : " https://localhost:8080/"
1015
+ },
1016
+ "id" : " uB8Kv6IHUzjJ" ,
1017
+ "outputId" : " 781304fc-30aa-44df-9540-ba1fbbdfed9d"
1018
+ },
1019
+ "execution_count" : 18 ,
1020
+ "outputs" : [
1021
+ {
1022
+ "output_type" : " stream" ,
1023
+ "name" : " stdout" ,
1024
+ "text" : [
1025
+ " Идентификаторы трех лучших вариантов: 125, 4, 44\n "
1026
+ ]
1027
+ }
1028
+ ]
1029
+ },
1030
+ {
1031
+ "cell_type" : " code" ,
1032
+ "source" : [
1033
+ " import pandas as pd\n " ,
1034
+ " import numpy as np\n " ,
1035
+ " \n " ,
1036
+ " data = pd.read_csv('/content/task4_1_939291.csv')\n " ,
1037
+ " \n " ,
1038
+ " data['distance_walk_norm'] = 1 - np.exp(1 - data['DISTANCE'] / data['DISTANCE'].min())\n " ,
1039
+ " data['metro_stations_norm'] = 1 - np.exp(1 - data['STOP_COUNT'] / data['STOP_COUNT'].min())\n " ,
1040
+ " data['rent_norm'] = 1 - np.exp(1 - data['COST'] / data['COST'].min())\n " ,
1041
+ " data['fitness_distance_norm'] = 1 - np.exp(1 - data['FITNESS'] / data['FITNESS'].min())\n " ,
1042
+ " data['internet_providers_norm'] = -1 * np.exp(1 - data['INTERNET'] / data['INTERNET'].max())\n " ,
1043
+ " \n " ,
1044
+ " data['target_value'] = (\n " ,
1045
+ " data['distance_walk_norm'] +\n " ,
1046
+ " data['metro_stations_norm'] +\n " ,
1047
+ " 0.2 * data['fitness_distance_norm'] +\n " ,
1048
+ " 0.4 * data['internet_providers_norm']\n " ,
1049
+ " )\n " ,
1050
+ " \n " ,
1051
+ " best_options = data.nsmallest(3, 'target_value')['ID'].tolist()\n " ,
1052
+ " \n " ,
1053
+ " best_options_str = \" ,\" .join(map(str, best_options))\n " ,
1054
+ " print(best_options_str)\n "
1055
+ ],
1056
+ "metadata" : {
1057
+ "colab" : {
1058
+ "base_uri" : " https://localhost:8080/"
1059
+ },
1060
+ "id" : " sPOx3Bz2nYwi" ,
1061
+ "outputId" : " f4eb3ace-9150-4a03-83f1-d0025474315d"
1062
+ },
1063
+ "execution_count" : 24 ,
1064
+ "outputs" : [
1065
+ {
1066
+ "output_type" : " stream" ,
1067
+ "name" : " stdout" ,
1068
+ "text" : [
1069
+ " 180,17,9\n "
1070
+ ]
1071
+ }
1072
+ ]
740
1073
}
741
1074
]
742
1075
}
0 commit comments