Verileri CSV/JSON'da Depolama
Kolay taşınabilirlik ve analiz için kazınan verileri CSV ve JSON gibi yaygın dosya biçimlerine kaydetmeyi öğrenin.
Verileri CSV/JSON'da Depolama, CoddyKit'te ücretsiz bir Web Scraping & Bots dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Web Scraping & Bots öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Web Scraping & Bots kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Storing Your Scraped Data
After scraping, raw data is often in memory. To use it later, share it, or analyze it, you need to save it permanently.
This lesson introduces two popular file formats: CSV and JSON. They are simple, human-readable, and widely supported.
Meet CSV: Comma-Separated Values
CSV stands for Comma-Separated Values. It's a plain text file format used to store tabular data, like a spreadsheet.
Each line in a CSV file is a data record. Each record consists of one or more fields, separated by commas.
CSV: Simple Table Format
Imagine a simple table. Each row becomes a line, and each column value is separated by a comma. The first line often contains the column headers.
name,age,city
Alice,30,New York
Bob,24,LondonWriting to CSV with Python
Python's built-in csv module makes writing data to CSV files easy. We'll use csv.writer and writerow().
The 'w' mode opens the file for writing. newline='' prevents extra blank rows.
import csv
# Data to save
data = [
["name", "age", "city"],
["Alice", 30, "New York"],
["Bob", 24, "London"]
]
# Open the file in write mode
with open("people.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerows(data) # Write all rows at once
print("Data saved to people.csv")JSON: JavaScript Object Notation
JSON (JavaScript Object Notation) is another popular, human-readable format. It's often used for sending data between web servers and web applications.
JSON organizes data into key-value pairs, similar to Python dictionaries, and lists.
JSON: Key-Value Pairs
JSON data is structured using objects ({}) and arrays ([]).
- An object holds key-value pairs (e.g.,
"name": "Alice"). - An array holds an ordered list of values (e.g.,
[{}, {}]).
[
{
"name": "Alice",
"age": 30,
"city": "New York"
},
{
"name": "Bob",
"age": 24,
"city": "London"
}
]Writing to JSON with Python
Python's built-in json module handles JSON data. We'll use json.dump() to write a Python dictionary or list to a file.
indent=2 makes the output file more readable by adding indentation.
import json
# Data to save (list of dictionaries)
data = [
{"name": "Alice", "age": 30, "city": "New York"},
{"name": "Bob", "age": 24, "city": "London"}
]
# Open the file in write mode
with open("people.json", "w") as file:
json.dump(data, file, indent=2)
print("Data saved to people.json")Choosing the Right Format
Both CSV and JSON are great for data storage, but they excel in different scenarios:
- CSV: Best for simple tabular data, like spreadsheets. Easy to import into databases or Excel.
- JSON: Ideal for complex, hierarchical data. Great for APIs and when data structure might vary.
Reading Data Back
Just as you can write data, you can also read it back! Both csv and json modules provide functions for this.
csv.reader()for CSV files.json.load()for JSON files.
This allows you to load your scraped data back into Python for further processing.
Data Format Quiz
Which file format is generally better suited for storing hierarchical data with nested structures, like a list of products where each product has multiple attributes and possibly sub-items?
Lesson Summary
You've learned how to persist your scraped data!
- CSV: Ideal for tabular data, easy with Python's
csvmodule. - JSON: Great for hierarchical data, handled by Python's
jsonmodule. - Choose the format that best fits your data's structure and how you plan to use it.
Saving data is crucial for analysis and future use.
Sıkça Sorulan Sorular
“Verileri CSV/JSON'da Depolama” dersi ücretsiz mi?
Evet — “Verileri CSV/JSON'da Depolama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Web Scraping & Bots kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Web Scraping & Bots kursu toplamda 4 dersten oluşur.
“Verileri CSV/JSON'da Depolama” dersinde ne öğreneceğim?
Kolay taşınabilirlik ve analiz için kazınan verileri CSV ve JSON gibi yaygın dosya biçimlerine kaydetmeyi öğrenin. Web Scraping & Bots ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Web Scraping & Bots öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Web Scraping & Bots, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“Verileri CSV/JSON'da Depolama” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Web Scraping & Bots dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Web Scraping & Bots dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Verileri CSV/JSON'da Depolama
- Veritabanlarıyla Entegrasyon (SQL)
- Bulut Depolama Çözümleri
- NoSQL Veritabanlarında Veri Depolama