Spaces:
Build error
Build error
File size: 9,095 Bytes
3a1020a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" _id id \\\n",
"0 {'$oid': '66c33a8c3b8bd216bd8ea93a'} 3525037 \n",
"1 {'$oid': '66c33a8c3b8bd216bd8ea93b'} 3532700 \n",
"2 {'$oid': '66c33a8c3b8bd216bd8ea93c'} 3203545 \n",
"3 {'$oid': '66c33a8c3b8bd216bd8ea93d'} 1765445 \n",
"4 {'$oid': '66c33a8c3b8bd216bd8ea93e'} 575462 \n",
"\n",
" url title \\\n",
"0 https://tr.wikipedia.org/wiki/P%C5%9F%C4%B1qo%... Pşıqo Ahecaqo \n",
"1 https://tr.wikipedia.org/wiki/Craterolophinae Craterolophinae \n",
"2 https://tr.wikipedia.org/wiki/Notocrabro Notocrabro \n",
"3 https://tr.wikipedia.org/wiki/Ibrahim%20Sissoko Ibrahim Sissoko \n",
"4 https://tr.wikipedia.org/wiki/Salah%20Cedid Salah Cedid \n",
"\n",
" text no \n",
"0 Pşıqo Ahecaqo (), Çerkes siyasetçi, askeri kom... 0 \n",
"1 Craterolophinae, Depastridae familyasına bağlı... 1 \n",
"2 Notocrabro Crabronina oymağına bağlı bir cinst... 2 \n",
"3 İbrahim Sissoko (d. 30 Kasım 1991), Fildişi Sa... 3 \n",
"4 Salah Cedid (1926-1993) (Arapça: صلاح جديد) Su... 4 \n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"# CSV dosyasını yükleyelim\n",
"df = pd.read_csv('veriler.csv')\n",
"\n",
"# ID sütunu ekleyelim (her satıra 0'dan başlayarak benzersiz bir ID verelim)\n",
"df['no'] = df.index\n",
"\n",
"# Sonucu yeni bir CSV dosyasına kaydedelim\n",
"df.to_csv('data_with_id.csv', index=False)\n",
"\n",
"# İlk birkaç satırı kontrol edelim\n",
"print(df.head())\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Boş değer sayısı:\n",
"_id 0\n",
"id 0\n",
"url 0\n",
"title 0\n",
"text 0\n",
"dtype: int64\n",
"Tekrarlanan değer sayısı:\n",
"0\n",
"Eşleşmeyen 'title' sayısı: 0\n",
"Eşleşmeyen 'text' sayısı: 0\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"# Verileri yükleyin\n",
"df = pd.read_csv(\"common_400000.csv\")\n",
"\n",
"# Boş değerlerin kontrolü\n",
"print(\"Boş değer sayısı:\")\n",
"print(df.isnull().sum())\n",
"\n",
"# Tekrarlanan değerlerin kontrolü\n",
"print(\"Tekrarlanan değer sayısı:\")\n",
"print(df.duplicated(subset=['title', 'text']).sum())\n",
"\n",
"# Eşleşmeyen değerlerin kontrolü\n",
"unmatched_titles = df[df['text'].isna()]\n",
"print(f\"Eşleşmeyen 'title' sayısı: {len(unmatched_titles)}\")\n",
"\n",
"unmatched_texts = df[df['title'].isna()]\n",
"print(f\"Eşleşmeyen 'text' sayısı: {len(unmatched_texts)}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Eksik 'text' değerlerini doldur\n",
"df['text'] = df['text'].fillna(\"Missing Text\")\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Tamamen aynı olan satırları kaldır\n",
"df = df.drop_duplicates(subset=['title', 'text'])\n",
"\n",
"# Sadece 'title' bazında tekrarlanan satırları kaldır (ilkini tutar)\n",
"df = df.drop_duplicates(subset=['title'], keep='first')\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Text'i olmayan satırları kaldır\n",
"df = df.dropna(subset=['text'])\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Veriler başarıyla converted_file.csv olarak kaydedildi.\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"# JSON dosyasını yükleyin\n",
"json_file = 'EgitimDatabase.train.json' # JSON dosyanızın adı\n",
"df = pd.read_json(json_file) # JSON dosyasını DataFrame'e dönüştürme\n",
"\n",
"# DataFrame'i CSV olarak kaydetme\n",
"csv_file = 'converted_file.csv' # Çıktı CSV dosya adı\n",
"df.to_csv(csv_file, index=False, encoding='utf-8') # index olmadan ve UTF-8 formatında kaydedilir\n",
"\n",
"print(f\"Veriler başarıyla {csv_file} olarak kaydedildi.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 416434 entries, 0 to 416433\n",
"Data columns (total 5 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 _id 416434 non-null object\n",
" 1 id 416434 non-null int64 \n",
" 2 url 416434 non-null object\n",
" 3 title 416434 non-null object\n",
" 4 text 416434 non-null object\n",
"dtypes: int64(1), object(4)\n",
"memory usage: 15.9+ MB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Boş text satırları: 1\n",
"Boş title satırları: 0\n"
]
}
],
"source": [
"# Boş değerleri kontrol etmek\n",
"empty_text_rows = df[df['text'].str.strip() == \"\"]\n",
"print(f\"Boş text satırları: {len(empty_text_rows)}\")\n",
"\n",
"empty_title_rows = df[df['title'].str.strip() == \"\"]\n",
"print(f\"Boş title satırları: {len(empty_title_rows)}\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Geçerli satır sayısı: 416434\n"
]
}
],
"source": [
"# Hem title hem text dolu olanları kontrol et\n",
"valid_rows = df[df['title'].notnull() & df['text'].notnull()]\n",
"print(f\"Geçerli satır sayısı: {len(valid_rows)}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"df['text'] = df['text'].apply(lambda x: str(x) if isinstance(x, dict) else x)\n",
"df['_id'] = df['_id'].apply(lambda x: str(x) if isinstance(x, dict) else x)\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tekrarlayan satır sayısı: 0\n"
]
}
],
"source": [
"# Tekrarlayan satırları kontrol etmek\n",
"duplicated_rows = df[df.duplicated()]\n",
"print(f\"Tekrarlayan satır sayısı: {len(duplicated_rows)}\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty DataFrame\n",
"Columns: [_id, id, url, title, text]\n",
"Index: []\n"
]
}
],
"source": [
"# Title ve text sütunlarında boş veya tutarsız değer var mı?\n",
"print(df[df['title'].isna() | df['text'].isna()])\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"df['text'] = df['text'].fillna('Eksik veri')\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"416434\n"
]
}
],
"source": [
"# Sütundaki benzersiz değerleri sayma\n",
"print(df['title'].nunique())"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"414397\n"
]
}
],
"source": [
"print(df['text'].nunique())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|