Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
75326daa85 | |||
790b584d49 |
413
.gitignore
vendored
413
.gitignore
vendored
@ -1,315 +1,4 @@
|
||||
|
||||
### LaTeX ###
|
||||
## Core latex/pdflatex auxiliary files:
|
||||
*.aux
|
||||
*.lof
|
||||
*.log
|
||||
*.lot
|
||||
*.fls
|
||||
*.out
|
||||
*.toc
|
||||
*.fmt
|
||||
*.fot
|
||||
*.cb
|
||||
*.cb2
|
||||
.*.lb
|
||||
|
||||
## Intermediate documents:
|
||||
*.dvi
|
||||
*.xdv
|
||||
*-converted-to.*
|
||||
# these rules might exclude image files for figures etc.
|
||||
# *.ps
|
||||
# *.eps
|
||||
# *.pdf
|
||||
|
||||
## Generated if empty string is given at "Please type another file name for output:"
|
||||
.pdf
|
||||
|
||||
## Bibliography auxiliary files (bibtex/biblatex/biber):
|
||||
*.bbl
|
||||
*.bcf
|
||||
*.blg
|
||||
*-blx.aux
|
||||
*-blx.bib
|
||||
*.run.xml
|
||||
|
||||
## Build tool auxiliary files:
|
||||
*.fdb_latexmk
|
||||
*.synctex
|
||||
*.synctex(busy)
|
||||
*.synctex.gz
|
||||
*.synctex.gz(busy)
|
||||
*.pdfsync
|
||||
|
||||
## Build tool directories for auxiliary files
|
||||
# latexrun
|
||||
latex.out/
|
||||
|
||||
## Auxiliary and intermediate files from other packages:
|
||||
# algorithms
|
||||
*.alg
|
||||
*.loa
|
||||
|
||||
# achemso
|
||||
acs-*.bib
|
||||
|
||||
# amsthm
|
||||
*.thm
|
||||
|
||||
# beamer
|
||||
*.nav
|
||||
*.pre
|
||||
*.snm
|
||||
*.vrb
|
||||
|
||||
# changes
|
||||
*.soc
|
||||
|
||||
# comment
|
||||
*.cut
|
||||
|
||||
# cprotect
|
||||
*.cpt
|
||||
|
||||
# elsarticle (documentclass of Elsevier journals)
|
||||
*.spl
|
||||
|
||||
# endnotes
|
||||
*.ent
|
||||
|
||||
# fixme
|
||||
*.lox
|
||||
|
||||
# feynmf/feynmp
|
||||
*.mf
|
||||
*.mp
|
||||
*.t[1-9]
|
||||
*.t[1-9][0-9]
|
||||
*.tfm
|
||||
|
||||
#(r)(e)ledmac/(r)(e)ledpar
|
||||
*.end
|
||||
*.?end
|
||||
*.[1-9]
|
||||
*.[1-9][0-9]
|
||||
*.[1-9][0-9][0-9]
|
||||
*.[1-9]R
|
||||
*.[1-9][0-9]R
|
||||
*.[1-9][0-9][0-9]R
|
||||
*.eledsec[1-9]
|
||||
*.eledsec[1-9]R
|
||||
*.eledsec[1-9][0-9]
|
||||
*.eledsec[1-9][0-9]R
|
||||
*.eledsec[1-9][0-9][0-9]
|
||||
*.eledsec[1-9][0-9][0-9]R
|
||||
|
||||
# glossaries
|
||||
*.acn
|
||||
*.acr
|
||||
*.glg
|
||||
*.glo
|
||||
*.gls
|
||||
*.glsdefs
|
||||
*.lzo
|
||||
*.lzs
|
||||
*.slg
|
||||
*.slo
|
||||
*.sls
|
||||
|
||||
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
|
||||
# *.ist
|
||||
|
||||
# gnuplot
|
||||
*.gnuplot
|
||||
*.table
|
||||
|
||||
# gnuplottex
|
||||
*-gnuplottex-*
|
||||
|
||||
# gregoriotex
|
||||
*.gaux
|
||||
*.glog
|
||||
*.gtex
|
||||
|
||||
# htlatex
|
||||
*.4ct
|
||||
*.4tc
|
||||
*.idv
|
||||
*.lg
|
||||
*.trc
|
||||
*.xref
|
||||
|
||||
# hyperref
|
||||
*.brf
|
||||
|
||||
# knitr
|
||||
*-concordance.tex
|
||||
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
|
||||
# *.tikz
|
||||
*-tikzDictionary
|
||||
|
||||
# listings
|
||||
*.lol
|
||||
|
||||
# luatexja-ruby
|
||||
*.ltjruby
|
||||
|
||||
# makeidx
|
||||
*.idx
|
||||
*.ilg
|
||||
*.ind
|
||||
|
||||
# minitoc
|
||||
*.maf
|
||||
*.mlf
|
||||
*.mlt
|
||||
*.mtc[0-9]*
|
||||
*.slf[0-9]*
|
||||
*.slt[0-9]*
|
||||
*.stc[0-9]*
|
||||
|
||||
# minted
|
||||
_minted*
|
||||
*.pyg
|
||||
|
||||
# morewrites
|
||||
*.mw
|
||||
|
||||
# newpax
|
||||
*.newpax
|
||||
|
||||
# nomencl
|
||||
*.nlg
|
||||
*.nlo
|
||||
*.nls
|
||||
|
||||
# pax
|
||||
*.pax
|
||||
|
||||
# pdfpcnotes
|
||||
*.pdfpc
|
||||
|
||||
# sagetex
|
||||
*.sagetex.sage
|
||||
*.sagetex.py
|
||||
*.sagetex.scmd
|
||||
|
||||
# scrwfile
|
||||
*.wrt
|
||||
|
||||
# svg
|
||||
svg-inkscape/
|
||||
|
||||
# sympy
|
||||
*.sout
|
||||
*.sympy
|
||||
sympy-plots-for-*.tex/
|
||||
|
||||
# pdfcomment
|
||||
*.upa
|
||||
*.upb
|
||||
|
||||
# pythontex
|
||||
*.pytxcode
|
||||
pythontex-files-*/
|
||||
|
||||
# tcolorbox
|
||||
*.listing
|
||||
|
||||
# thmtools
|
||||
*.loe
|
||||
|
||||
# TikZ & PGF
|
||||
*.dpth
|
||||
*.md5
|
||||
*.auxlock
|
||||
|
||||
# titletoc
|
||||
*.ptc
|
||||
|
||||
# todonotes
|
||||
*.tdo
|
||||
|
||||
# vhistory
|
||||
*.hst
|
||||
*.ver
|
||||
|
||||
# easy-todo
|
||||
*.lod
|
||||
|
||||
# xcolor
|
||||
*.xcp
|
||||
|
||||
# xmpincl
|
||||
*.xmpi
|
||||
|
||||
# xindy
|
||||
*.xdy
|
||||
|
||||
# xypic precompiled matrices and outlines
|
||||
*.xyc
|
||||
*.xyd
|
||||
|
||||
# endfloat
|
||||
*.ttt
|
||||
*.fff
|
||||
|
||||
# Latexian
|
||||
TSWLatexianTemp*
|
||||
|
||||
## Editors:
|
||||
# WinEdt
|
||||
*.bak
|
||||
*.sav
|
||||
|
||||
# Texpad
|
||||
.texpadtmp
|
||||
|
||||
# LyX
|
||||
*.lyx~
|
||||
|
||||
# Kile
|
||||
*.backup
|
||||
|
||||
# gummi
|
||||
.*.swp
|
||||
|
||||
# KBibTeX
|
||||
*~[0-9]*
|
||||
|
||||
# TeXnicCenter
|
||||
*.tps
|
||||
|
||||
# auto folder when using emacs and auctex
|
||||
./auto/*
|
||||
*.el
|
||||
|
||||
# expex forward references with \gathertags
|
||||
*-tags.tex
|
||||
|
||||
# standalone packages
|
||||
*.sta
|
||||
|
||||
# Makeindex log files
|
||||
*.lpz
|
||||
|
||||
# xwatermark package
|
||||
*.xwm
|
||||
|
||||
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
|
||||
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
|
||||
# Uncomment the next line to have this generated file ignored.
|
||||
#*Notes.bib
|
||||
|
||||
### LaTeX Patch ###
|
||||
# LIPIcs / OASIcs
|
||||
*.vtc
|
||||
|
||||
# glossaries
|
||||
*.glstex
|
||||
|
||||
### Python ###
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
@ -368,6 +57,7 @@ cover/
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
@ -470,102 +160,3 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
### Python Patch ###
|
||||
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||
poetry.toml
|
||||
|
||||
# ruff
|
||||
.ruff_cache/
|
||||
|
||||
# LSP config files
|
||||
pyrightconfig.json
|
||||
|
||||
# Audio files
|
||||
*.mp3
|
||||
*.wav
|
||||
*.flac
|
||||
*.aac
|
||||
*.ogg
|
||||
*.m4a
|
||||
*.wma
|
||||
|
||||
# Video files
|
||||
*.mp4
|
||||
*.mov
|
||||
*.avi
|
||||
*.mkv
|
||||
*.flv
|
||||
*.wmv
|
||||
*.webm
|
||||
*.mpeg
|
||||
*.mpg
|
||||
*.m4v
|
||||
|
||||
# Image files
|
||||
*.jpg
|
||||
*.jpeg
|
||||
*.png
|
||||
*.gif
|
||||
*.bmp
|
||||
*.tiff
|
||||
*.tif
|
||||
*.svg
|
||||
*.webp
|
||||
|
||||
# RAW image formats
|
||||
*.cr2
|
||||
*.nef
|
||||
*.arw
|
||||
*.dng
|
||||
*.rw2
|
||||
|
||||
# Video project files (optional)
|
||||
*.proj
|
||||
*.prproj
|
||||
*.aep
|
||||
*.veg
|
||||
*.imovieproj
|
||||
|
||||
# 3D Model and animation formats (optional)
|
||||
*.obj
|
||||
*.fbx
|
||||
*.dae
|
||||
*.blend
|
||||
*.3ds
|
||||
*.stl
|
||||
|
||||
# Word processor documents
|
||||
*.doc
|
||||
*.docx
|
||||
*.odt
|
||||
*.rtf
|
||||
*.wps
|
||||
|
||||
# Spreadsheet documents
|
||||
*.xls
|
||||
*.xlsx
|
||||
*.ods
|
||||
*.csv
|
||||
|
||||
# Presentation documents
|
||||
*.ppt
|
||||
*.pptx
|
||||
*.odp
|
||||
|
||||
# PDF files
|
||||
*.pdf
|
||||
|
||||
# Other office-related formats
|
||||
*.pub
|
||||
*.vsd
|
||||
*.vsdx
|
||||
*.key
|
||||
*.numbers
|
||||
*.pages
|
||||
|
||||
# Archive and compressed files (optional, in case they generate them)
|
||||
*.zip
|
||||
*.rar
|
||||
*.tar
|
||||
*.gz
|
||||
*.7z
|
||||
|
@ -1,8 +1,6 @@
|
||||
# Data Analysis Structure Guide
|
||||
# Data Analysis Project Structure Guide
|
||||
|
||||
**German version**: [README_DE.md](README_de.md)
|
||||
|
||||
Welcome to our Project Structure Guide! This guide is designed to
|
||||
Welcome to the Data Analysis Project Structure Guide! This guide is designed to
|
||||
help new students understand how to structure data analysis projects in Python
|
||||
effectively. By following these best practices, you'll create projects that are
|
||||
organized, maintainable, and reproducible.
|
||||
|
223
README_de.md
223
README_de.md
@ -1,223 +0,0 @@
|
||||
# Leitfaden zur Datenanalyse-Struktur
|
||||
|
||||
Willkommen zu diesem Leitfaden zur Projektstruktur! Dieser Leitfaden soll dir helfen zu verstehen, wie du Datenanalyseprojekte in Python effektiv strukturierst.
|
||||
|
||||
## Inhaltsverzeichnis
|
||||
|
||||
1. [Projektstruktur](#projektstruktur)
|
||||
- [Trennung von Daten und Code](#trennung-von-daten-und-code)
|
||||
- [Trennung von Abbildungen und Code](#trennung-von-abbildungen-und-code)
|
||||
2. [Versionskontrolle mit Git](#versionskontrolle-mit-git)
|
||||
- [Grundlegende Git-Befehle](#grundlegende-git-befehle)
|
||||
3. [Best Practices für Datenanalyseprojekte](#best-practices-für-datenanalyseprojekte)
|
||||
4. [Zusätzliche Ressourcen](#zusätzliche-ressourcen)
|
||||
5. [Fazit](#fazit)
|
||||
|
||||
---
|
||||
|
||||
## Projektstruktur
|
||||
|
||||
Eine gut organisierte Projektstruktur ist entscheidend für Zusammenarbeit und Skalierbarkeit. Hier ist ein empfohlenes Verzeichnislayout:
|
||||
|
||||
```
|
||||
project-name/
|
||||
├── data/
|
||||
│ ├── model_weights/ # Trainierte Modellgewichte
|
||||
│ ├── raw/ # Originale, unveränderte Datensätze
|
||||
│ └── processed/ # Bereinigte oder transformierte Daten
|
||||
├── code/
|
||||
│ └── my_python_program.py # Python-Skripte
|
||||
├── figures/
|
||||
├── docs/
|
||||
│ ├── my_fancy_latex_thesis/ # LaTeX-Dateien für die Abschlussarbeit (empfohlen)
|
||||
│ ├── my_presentation.pptx # Präsentationsfolien
|
||||
│ └── my_thesis.docx # Word-Dokument (nicht empfohlen)
|
||||
├── .gitignore # Dateien und Verzeichnisse, die von Git ignoriert werden sollen
|
||||
├── README.md # Projektübersicht und Anleitungen
|
||||
└── requirements.txt # Python-Abhängigkeiten
|
||||
```
|
||||
|
||||
### Trennung von Daten und Code
|
||||
|
||||
- **Datenverzeichnis (`data/`)**: Speichere hier alle deine Datensätze.
|
||||
- `raw/`: Originale, unveränderte Datensätze.
|
||||
- `processed/`: Daten, die bereinigt oder transformiert wurden.
|
||||
- **Quellcode-Verzeichnis (`code/`)**: Enthält alle Codeskripte und Module.
|
||||
|
||||
**Vorteile:**
|
||||
|
||||
- **Organisation**: Hält Daten getrennt vom Code, was die Verwaltung erleichtert.
|
||||
- **Reproduzierbarkeit**: Klare Trennung stellt sicher, dass Datenverarbeitungsschritte dokumentiert und wiederholbar sind.
|
||||
- **Zusammenarbeit**: Du und deine Kollaborateure können leicht verschiedene Komponenten des Projekts finden und verstehen.
|
||||
|
||||
### Trennung von Abbildungen und Code
|
||||
|
||||
- **Abbildungsverzeichnis (`figures/`)**: Speichere hier alle generierten Plots, Bilder und Visualisierungen.
|
||||
|
||||
**Vorteile:**
|
||||
|
||||
- **Klarheit**: Trennt Ausgaben vom Code und reduziert Unordnung.
|
||||
- **Versionskontrolle**: Einfachere Nachverfolgung von Änderungen im Code ohne große Binärdateien wie Bilder.
|
||||
- **Präsentation**: Vereinfacht das Erstellen von Berichten oder Präsentationen, indem alle Abbildungen an einem Ort gesammelt sind.
|
||||
|
||||
---
|
||||
|
||||
## Versionskontrolle mit Git
|
||||
|
||||
Git ist ein leistungsstarkes Versionskontrollsystem, das dir hilft, Änderungen zu verfolgen, mit anderen zusammenzuarbeiten und die Historie deines Projekts zu verwalten. Aber was ist Versionskontrolle? Hast du jemals Dateien wie `project_final_v2.py` oder `project_final_final.py` erstellt? Versionskontrolle löst dieses Problem, indem sie Änderungen verfolgt und dir ermöglicht, zu früheren Versionen zurückzukehren. Als Bonus hast du auch ein Backup deines Projekts, falls etwas schiefgeht.
|
||||
|
||||
### Grundlegende Git-Befehle
|
||||
|
||||
- **Ein Repository initialisieren**
|
||||
|
||||
```bash
|
||||
git init
|
||||
```
|
||||
|
||||
- **Remote-Repository hinzufügen (GitHub, Gittea)**
|
||||
|
||||
```bash
|
||||
git remote add origin <repository-url>
|
||||
```
|
||||
|
||||
- **Ein Repository klonen**
|
||||
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
```
|
||||
|
||||
- **Status prüfen**
|
||||
|
||||
```bash
|
||||
git status
|
||||
```
|
||||
|
||||
- **Änderungen hinzufügen**
|
||||
|
||||
```bash
|
||||
git add <dateiname>
|
||||
# Oder alle Änderungen hinzufügen
|
||||
git add .
|
||||
```
|
||||
|
||||
- **Änderungen committen**
|
||||
|
||||
```bash
|
||||
git commit -m "Commit-Nachricht"
|
||||
```
|
||||
|
||||
- **Zum Remote-Repository pushen**
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
- **Vom Remote-Repository pullen**
|
||||
|
||||
```bash
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
#### Erweiterte Git-Befehle
|
||||
|
||||
- **Einen neuen Branch erstellen**
|
||||
|
||||
```bash
|
||||
git branch <branch-name>
|
||||
```
|
||||
|
||||
- **Zwischen Branches wechseln**
|
||||
|
||||
```bash
|
||||
git checkout <branch-name>
|
||||
```
|
||||
|
||||
- **Branches zusammenführen**
|
||||
|
||||
```bash
|
||||
git merge <branch-name>
|
||||
```
|
||||
|
||||
- **Commit-Historie anzeigen**
|
||||
|
||||
```bash
|
||||
git log
|
||||
```
|
||||
|
||||
**Tipps:**
|
||||
|
||||
- **Oft committen**: Regelmäßige Commits erleichtern das Nachverfolgen von Änderungen.
|
||||
- **Aussagekräftige Nachrichten**: Verwende beschreibende Commit-Nachrichten für besseres Verständnis.
|
||||
- **Verwende `.gitignore`**: Schließe Dateien und Verzeichnisse aus, die nicht verfolgt werden sollten (z. B. große Datendateien, virtuelle Umgebungen).
|
||||
|
||||
---
|
||||
|
||||
## Best Practices für Datenanalyseprojekte
|
||||
|
||||
1. **Verwende virtuelle Umgebungen**
|
||||
|
||||
- Nutze `venv`, `conda` oder `pyenv`, um projektspezifische Abhängigkeiten zu verwalten.
|
||||
- Dokumentiere Abhängigkeiten in `requirements.txt` oder verwende `poetry` für das Paketmanagement.
|
||||
|
||||
2. **Dokumentiere deine Arbeit**
|
||||
|
||||
- Pflege eine klare und informative `README.md`.
|
||||
- Verwende Docstrings und Kommentare in deinem Code.
|
||||
- Führe ein Changelog für bedeutende Updates.
|
||||
|
||||
3. **Schreibe modularen Code**
|
||||
|
||||
- Unterteile Code in Funktionen und Klassen.
|
||||
- Nutze Code wieder, um Duplikate zu vermeiden.
|
||||
|
||||
4. **Befolge Codierungsstandards**
|
||||
|
||||
- Halte dich an die PEP 8-Richtlinien für Python-Code.
|
||||
- Verwende Linter wie `flake8` oder Formatter wie `black` oder `ruff`, um die Codequalität zu gewährleisten.
|
||||
|
||||
5. **Automatisiere die Datenverarbeitung**
|
||||
|
||||
- Schreibe Skripte, um die Datenbereinigung und -vorverarbeitung zu automatisieren.
|
||||
- Stelle sicher, dass Skripte von Anfang bis Ende ausgeführt werden können, um Ergebnisse zu reproduzieren.
|
||||
|
||||
6. **Teste deinen Code**
|
||||
|
||||
- Implementiere Unit-Tests mit Frameworks wie `unittest` oder `pytest`.
|
||||
- Halte Tests im Verzeichnis `tests/`.
|
||||
|
||||
7. **Gehe sorgfältig mit Daten um**
|
||||
|
||||
- Committe keine Daten in die Versionskontrolle.
|
||||
|
||||
8. **Versioniere Daten und Modelle**
|
||||
|
||||
- Speichere Modellversionen mit Zeitstempeln oder eindeutigen Kennungen.
|
||||
|
||||
9. **Sichere regelmäßig**
|
||||
|
||||
- Pushe Änderungen häufig in ein Remote-Repository.
|
||||
- Erwäge zusätzliche Backups für kritische Daten.
|
||||
|
||||
10. **Arbeite effektiv zusammen**
|
||||
|
||||
- Verwende Branches für neue Funktionen oder Experimente.
|
||||
- Führe Änderungen mit Pull Requests und Code Reviews zusammen.
|
||||
|
||||
---
|
||||
|
||||
## Zusätzliche Ressourcen
|
||||
|
||||
- **Git-Dokumentation**: [git-scm.com/docs](https://git-scm.com/docs)
|
||||
- **PEP 8 Style Guide**: [python.org/dev/peps/pep-0008](https://www.python.org/dev/peps/pep-0008/)
|
||||
- **Python Virtual Environments**:
|
||||
- [`venv` Modul](https://docs.python.org/3/library/venv.html)
|
||||
- [Anaconda Distribution](https://www.anaconda.com/products/distribution)
|
||||
- [`pyenv` Virtuelle Umgebungen](https://github.com/pyenv/pyenv)
|
||||
|
||||
---
|
||||
|
||||
## Fazit
|
||||
|
||||
Die effektive Strukturierung deiner Datenanalyseprojekte ist der erste Schritt zu erfolgreicher und reproduzierbarer Forschung. Indem du Daten, Code und Abbildungen trennst, Versionskontrolle verwendest und bewährte Methoden befolgst, legst du ein starkes Fundament für deine Arbeit und die Zusammenarbeit mit anderen.
|
||||
|
||||
Viel Spaß beim Programmieren!
|
315
code/README.md
315
code/README.md
@ -1,303 +1,48 @@
|
||||
# Writing a Good Python Script: A Primer
|
||||
# Structure of a script
|
||||
|
||||
German version: [README_de.md](README_de.md)
|
||||
1. Initially you should specify which packages you use in the scripts
|
||||
|
||||
This primer will guide you through best practices to write effective and clean
|
||||
Python scripts. Whether you're working on a data processing pipeline, a machine
|
||||
learning model, or a simple utility script, following these guidelines will
|
||||
help you create maintainable and readable code.
|
||||
~~~python
|
||||
import pathlib # Packages that are provided from python
|
||||
|
||||
## 1. Use a Declarative and Meaningful Script Name
|
||||
import numpy as np # Packages that are downloaded, specified in the requierements.txt
|
||||
|
||||
Choose a script name that clearly describes its purpose. This makes it easier
|
||||
for others (and yourself) to understand what the script does without reading
|
||||
the code.
|
||||
import myscript # Scripts from your Project/Pipeline
|
||||
~~~
|
||||
|
||||
**Examples:**
|
||||
|
||||
- `data_cleaning.py` instead of `script1.py`
|
||||
- `generate_report.py` instead of `run.py`
|
||||
2. Next your code for the specific problem that you are trying to solve, all written code should be containded in a function/classes
|
||||
It should contain a main function with is calling all individual function to solve the problem.
|
||||
|
||||
## 2. Start with a Short Explanation (Docstring)
|
||||
~~~python
|
||||
def load_data(path):
|
||||
with open(path, "r") as f:
|
||||
f.read()
|
||||
return f
|
||||
|
||||
At the beginning of your script, include a docstring that briefly explains what the script does. This helps users quickly grasp the script's functionality.
|
||||
def main(path):
|
||||
load_data(path)
|
||||
~~~
|
||||
|
||||
```python
|
||||
"""
|
||||
This script loads raw data, cleans it by removing null values and duplicates,
|
||||
and saves the processed data to a new file.
|
||||
"""
|
||||
```
|
||||
|
||||
## 3. Import All Required Packages at the Beginning
|
||||
|
||||
List all your imports at the top of the script. This makes dependencies clear and simplifies maintenance.
|
||||
|
||||
```python
|
||||
import sys # Packages that are provided by Python
|
||||
from pathlib import Path
|
||||
import numpy as np # Packages that are downloaded, specified in the requierements.txt
|
||||
import pandas as pd
|
||||
import my_module # Modules that are written by yourself
|
||||
```
|
||||
|
||||
## 4. Encapsulate Code in Functions and Classes
|
||||
|
||||
Organize your code by wrapping functionality within functions or classes. This
|
||||
promotes code reuse, testing, and readability. Ideally, functions should do one
|
||||
thing and do it well. Classes can be used for more complex logic or when you need
|
||||
to maintain state. Clean functions and classes contain type hints and docstrings
|
||||
to explain their purpose and inputs/outputs.
|
||||
|
||||
**Examples of Functions:**
|
||||
|
||||
```python
|
||||
def load_data(file_path: str) -> pd.DataFrame:
|
||||
"""Loads data from a CSV file.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
file_path : str
|
||||
Path to the CSV file.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Loaded data as a DataFrame.
|
||||
"""
|
||||
return pd.read_csv(file_path)
|
||||
|
||||
def clean_data(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Cleans the DataFrame by removing null values and duplicates.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Input DataFrame.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Cleaned DataFrame.
|
||||
"""
|
||||
df = df.dropna()
|
||||
df = df.drop_duplicates()
|
||||
return df
|
||||
|
||||
def save_data(df: pd.DataFrame, output_path: str) -> None:
|
||||
"""Saves the DataFrame to a CSV file.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
DataFrame to save.
|
||||
output_path : str
|
||||
Path to save the CSV file.
|
||||
"""
|
||||
df.to_csv(output_path, index=False)
|
||||
```
|
||||
|
||||
**Example of a Class:**
|
||||
|
||||
```python
|
||||
class DataProcessor:
|
||||
"""A class for processing data."""
|
||||
|
||||
def __init__(self, file_path):
|
||||
self.data = self.load_data(file_path)
|
||||
|
||||
def load_data(self, file_path):
|
||||
return pd.read_csv(file_path)
|
||||
|
||||
def clean_data(self):
|
||||
self.data.dropna(inplace=True)
|
||||
self.data.drop_duplicates(inplace=True)
|
||||
|
||||
def save_data(self, output_path):
|
||||
self.data.to_csv(output_path, index=False)
|
||||
```
|
||||
|
||||
## 5. Define a `main()` Function
|
||||
|
||||
Create a `main()` function that serves as the entry point of your script. This
|
||||
function should orchestrate the flow of your program.
|
||||
|
||||
```python
|
||||
def main():
|
||||
"""Main function that orchestrates the data processing."""
|
||||
input_file = 'data/raw/data.csv'
|
||||
output_file = 'data/processed/clean_data.csv'
|
||||
|
||||
# Using functions
|
||||
data = load_data(input_file)
|
||||
clean_data = clean_data(data)
|
||||
save_data(clean_data, output_file)
|
||||
|
||||
# Or using a class
|
||||
# processor = DataProcessor(input_file)
|
||||
# processor.clean_data()
|
||||
# processor.save_data(output_file)
|
||||
|
||||
print("Data processing complete.")
|
||||
```
|
||||
|
||||
## 6. Use the `if __name__ == "__main__":` Statement
|
||||
|
||||
This is a common Python idiom that allows you to check if the script is being
|
||||
run as the main program. This ensures that the `main()` function is only called
|
||||
when the script is executed directly. If you execute the `main()` function
|
||||
directly, it will be executed when the module, or just parts of it, are
|
||||
imported in another script.
|
||||
|
||||
So at the end of your script, add:
|
||||
|
||||
```python
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
This checks if the script is being run as the main program and calls `main()` accordingly.
|
||||
|
||||
## Putting It All Together
|
||||
|
||||
Here's how your script might look when you combine all these best practices:
|
||||
|
||||
```python
|
||||
"""
|
||||
This script loads raw data, cleans it by removing null values and duplicates, and saves the processed data to a new file.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def load_data(file_path: str) -> pd.DataFrame:
|
||||
"""Loads data from a CSV file.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
file_path : str
|
||||
Path to the CSV file.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Loaded data as a DataFrame.
|
||||
"""
|
||||
return pd.read_csv(file_path)
|
||||
|
||||
def clean_data(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Cleans the DataFrame by removing null values and duplicates.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Input DataFrame.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Cleaned DataFrame.
|
||||
"""
|
||||
df = df.dropna()
|
||||
df = df.drop_duplicates()
|
||||
return df
|
||||
|
||||
def save_data(df: pd.DataFrame, output_path: str) -> None:
|
||||
"""Saves the DataFrame to a CSV file.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
DataFrame to save.
|
||||
output_path : str
|
||||
Path to save the CSV file.
|
||||
"""
|
||||
df.to_csv(output_path, index=False)
|
||||
|
||||
def main():
|
||||
"""Main function that orchestrates the data processing."""
|
||||
input_file = 'data/raw/data.csv'
|
||||
output_file = 'data/processed/clean_data.csv'
|
||||
|
||||
data = load_data(input_file)
|
||||
clean_data = clean_data(data)
|
||||
save_data(clean_data, output_file)
|
||||
|
||||
print("Data processing complete.")
|
||||
3. If the script is a standalone script, it can be run by calling python myscript.py it should contain...
|
||||
|
||||
~~~python
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
## Additional Tips
|
||||
|
||||
- **Comment Your Code:** Use comments to explain non-obvious parts of your code. However, strive to write code that is self-explanatory.
|
||||
- **Follow PEP 8 Guidelines:** Adhere to the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide for Python code to improve readability. To make this easy, use an auto-formatter like `black` or `ruff`.
|
||||
- **Use Meaningful Variable, Function and ClasE Names:** Choose names that convey their purpose. Avoid single-letter variable names except for simple iterators. Instead of `x` and `y` use e.g., `time` and `signal`.
|
||||
- **Handle Exceptions:** Use try-except blocks to handle potential errors gracefully.
|
||||
|
||||
```python
|
||||
try:
|
||||
data = load_data(input_file)
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The file {input_file} was not found.")
|
||||
sys.exit(1)
|
||||
```
|
||||
|
||||
- **Use Logging Instead of Print Statements:** For larger scripts, consider using the `logging` module for better control over logging levels and outputs.
|
||||
|
||||
```python
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
logging.info("Data processing complete.")
|
||||
```
|
||||
|
||||
- **Parameterize Your Scripts:** Use command-line arguments or a configuration file to make your script more flexible.
|
||||
|
||||
```python
|
||||
import argparse
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description="Process and clean data.")
|
||||
parser.add_argument('--input', required=True, help='Input file path')
|
||||
parser.add_argument('--output', required=True, help='Output file path')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
data = load_data(args.input)
|
||||
clean_data = clean_data(data)
|
||||
save_data(clean_data, args.output)
|
||||
```
|
||||
path = "../data/README.md"
|
||||
main(path)
|
||||
~~~
|
||||
|
||||
- **Make Your Code Modular:** Break down your script into multiple files or
|
||||
modules for better organization and reusability. For example, move data
|
||||
processing functions that are used in multiple scripts to a separate module
|
||||
called `data_processing.py`.
|
||||
|
||||
- **Coding a figure:** If you are coding a figure, you can follow our [coding
|
||||
a figure
|
||||
guide](https://github.com/bendalab/plottools/blob/master/docs/guide.md).
|
||||
Applying the same principles to your figure code will make it easier to
|
||||
modify and reuse.
|
||||
|
||||
# Tips and tricks
|
||||
- Plotting scripts should be named the same as the output figure for easier backtracking
|
||||
- Plotting scripts should start with plot, so that one can create a bash script for that executes all plot* scripts
|
||||
- If you use a directory for managing specific task, in python it is called a module, you neeed a __init__.py file in the directory more in [packagehowto](https://whale.am28.uni-tuebingen.de/git/pweygoldt/packagehowto)
|
||||
|
||||
## Conclusion
|
||||
# Naming conventions
|
||||
- Use snake_case for functions and variables
|
||||
|
||||
By following these best practices, you'll create Python scripts that are:
|
||||
# Documentation
|
||||
- Use docstrings for all functions and classes
|
||||
|
||||
- **Readable:** Clear structure and naming make your code easy to understand.
|
||||
- **Maintainable:** Encapsulation and modularity simplify updates and debugging.
|
||||
- **Reusable:** Functions and classes can be imported and used in other scripts.
|
||||
- **Robust:** Error handling ensures your script can handle unexpected situations gracefully.
|
||||
|
||||
Remember, good coding practices not only make your life easier but also help
|
||||
others who may work with your code in the future. The effort you put into
|
||||
writing clean and effective scripts will pay off in the long run.
|
||||
|
||||
Happy coding!
|
||||
|
||||
|
@ -1,275 +0,0 @@
|
||||
# Ein Leitfaden zum Schreiben eines guten Python-Skripts
|
||||
|
||||
Dieser Leitfaden hilft dir dabei, effektive und saubere Python-Skripte zu schreiben. Egal, ob du an einer Datenverarbeitungspipeline, einem Machine-Learning-Modell oder einem einfachen Hilfsskript arbeitest – wenn du diese Richtlinien befolgst, erstellst du lesbaren code, der leicht zu warten und zu erweitern ist.
|
||||
|
||||
## 1. Verwende einen aussagekräftigen und deklarativen Skriptnamen
|
||||
|
||||
Wähle einen Skriptnamen, der klar beschreibt, was das Skript tut. So ist es für andere (und dich selbst) einfacher zu verstehen, was das Skript macht, ohne den Code lesen zu müssen.
|
||||
|
||||
**Beispiele:**
|
||||
|
||||
- `datenbereinigung.py` statt `skript1.py`
|
||||
- `bericht_generieren.py` statt `run.py`
|
||||
|
||||
## 2. Beginne mit einer kurzen Erklärung (Docstring)
|
||||
|
||||
Füge am Anfang deines Skripts einen Docstring ein, der kurz erklärt, was das Skript macht. Das hilft Nutzern, die Funktionalität des Skripts schnell zu erfassen.
|
||||
|
||||
```python
|
||||
"""
|
||||
Dieses Skript lädt Rohdaten, bereinigt sie durch Entfernen von Nullwerten und Duplikaten und speichert die verarbeiteten Daten in einer neuen Datei.
|
||||
"""
|
||||
```
|
||||
|
||||
## 3. Importiere alle benötigten Pakete am Anfang
|
||||
|
||||
Liste alle deine Importe am Anfang des Skripts auf. Das macht Abhängigkeiten klar und vereinfacht die Wartung.
|
||||
|
||||
```python
|
||||
import sys # Pakete, die von Python bereitgestellt werden
|
||||
from pathlib import Path
|
||||
import numpy as np # Pakete, die heruntergeladen und in requirements.txt angegeben sind
|
||||
import pandas as pd
|
||||
import mein_modul # Module, die du selbst geschrieben hast
|
||||
```
|
||||
|
||||
## 4. Organisiere Code in Funktionen und Klassen
|
||||
|
||||
Organisiere deinen Code, indem du Funktionalitäten in Funktionen oder Klassen einbettest. Das fördert Code-Wiederverwendung, Testbarkeit und Lesbarkeit. Idealerweise sollten Funktionen eine Aufgabe erledigen und diese gut machen. Klassen können für komplexere Logik oder wenn du einen Zustand beibehalten musst, verwendet werden. Saubere Funktionen und Klassen enthalten _Type-Hints_ und _Docstrings_, um ihren Zweck sowie Eingaben/Ausgaben zu erklären.
|
||||
|
||||
**Beispiele für Funktionen:**
|
||||
|
||||
```python
|
||||
def lade_daten(dateipfad: str) -> pd.DataFrame:
|
||||
"""Lädt Daten aus einer CSV-Datei.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
dateipfad : str
|
||||
Pfad zur CSV-Datei.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Geladene Daten als DataFrame.
|
||||
"""
|
||||
return pd.read_csv(dateipfad)
|
||||
|
||||
def bereinige_daten(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Bereinigt den DataFrame durch Entfernen von Nullwerten und Duplikaten.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Eingabe-DataFrame.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Bereinigter DataFrame.
|
||||
"""
|
||||
df = df.dropna()
|
||||
df = df.drop_duplicates()
|
||||
return df
|
||||
|
||||
def speichere_daten(df: pd.DataFrame, ausgabepfad: str) -> None:
|
||||
"""Speichert den DataFrame in einer CSV-Datei.
|
||||
|
||||
Parameters:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Zu speichernder DataFrame.
|
||||
ausgabepfad : str
|
||||
Pfad zum Speichern der CSV-Datei.
|
||||
"""
|
||||
df.to_csv(ausgabepfad, index=False)
|
||||
```
|
||||
|
||||
**Beispiel für eine Klasse:**
|
||||
|
||||
```python
|
||||
class DatenVerarbeiter:
|
||||
"""Eine Klasse zur Datenverarbeitung."""
|
||||
|
||||
def __init__(self, dateipfad):
|
||||
self.daten = self.lade_daten(dateipfad)
|
||||
|
||||
def lade_daten(self, dateipfad):
|
||||
return pd.read_csv(dateipfad)
|
||||
|
||||
def bereinige_daten(self):
|
||||
self.daten.dropna(inplace=True)
|
||||
self.daten.drop_duplicates(inplace=True)
|
||||
|
||||
def speichere_daten(self, ausgabepfad):
|
||||
self.daten.to_csv(ausgabepfad, index=False)
|
||||
```
|
||||
|
||||
## 5. Definiere eine `main()`-Funktion
|
||||
|
||||
Erstelle eine `main()`-Funktion, die als Einstiegspunkt deines Skripts dient. Diese Funktion sollte den Ablauf deines Programms orchestrieren.
|
||||
|
||||
```python
|
||||
def main():
|
||||
"""Hauptfunktion, die die Datenverarbeitung steuert."""
|
||||
eingabedatei = 'data/raw/data.csv'
|
||||
ausgabedatei = 'data/processed/bereinigte_daten.csv'
|
||||
|
||||
# Verwendung von Funktionen
|
||||
daten = lade_daten(eingabedatei)
|
||||
bereinigte_daten = bereinige_daten(daten)
|
||||
speichere_daten(bereinigte_daten, ausgabedatei)
|
||||
|
||||
# Oder Verwendung einer Klasse
|
||||
# verarbeiter = DatenVerarbeiter(eingabedatei)
|
||||
# verarbeiter.bereinige_daten()
|
||||
# verarbeiter.speichere_daten(ausgabedatei)
|
||||
|
||||
print("Datenverarbeitung abgeschlossen.")
|
||||
```
|
||||
|
||||
## 6. Verwende die `if __name__ == "__main__":`-Anweisung
|
||||
|
||||
Dies ist ein gängiges Python-Idiom, mit dem du prüfen kannst, ob das Skript als Hauptprogramm ausgeführt wird. So stellst du sicher, dass die `main()`-Funktion nur aufgerufen wird, wenn das Skript direkt ausgeführt wird. Wenn du die `main()`-Funktion direkt ausführst, wird sie nicht ausgeführt, wenn das Modul oder Teile davon in einem anderen Skript importiert werden.
|
||||
|
||||
Füge also am Ende deines Skripts hinzu:
|
||||
|
||||
```python
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
Dies prüft, ob das Skript als Hauptprogramm ausgeführt wird, und ruft entsprechend `main()` auf.
|
||||
|
||||
## Alles zusammenführen
|
||||
|
||||
So könnte dein Skript aussehen, wenn du all diese Best Practices kombinierst:
|
||||
|
||||
```python
|
||||
"""
|
||||
Dieses Skript lädt Rohdaten, bereinigt sie durch Entfernen von Nullwerten und Duplikaten, und speichert die verarbeiteten Daten in einer neuen Datei.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def lade_daten(dateipfad: str) -> pd.DataFrame:
|
||||
"""Lädt Daten aus einer CSV-Datei.
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
dateipfad : str
|
||||
Pfad zur CSV-Datei.
|
||||
|
||||
Rückgabe:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Geladene Daten als DataFrame.
|
||||
"""
|
||||
return pd.read_csv(dateipfad)
|
||||
|
||||
def bereinige_daten(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"""Bereinigt den DataFrame durch Entfernen von Nullwerten und Duplikaten.
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Eingabe-DataFrame.
|
||||
|
||||
Rückgabe:
|
||||
-------
|
||||
pd.DataFrame
|
||||
Bereinigter DataFrame.
|
||||
"""
|
||||
df = df.dropna()
|
||||
df = df.drop_duplicates()
|
||||
return df
|
||||
|
||||
def speichere_daten(df: pd.DataFrame, ausgabepfad: str) -> None:
|
||||
"""Speichert den DataFrame in einer CSV-Datei.
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
Zu speichernder DataFrame.
|
||||
ausgabepfad : str
|
||||
Pfad zum Speichern der CSV-Datei.
|
||||
"""
|
||||
df.to_csv(ausgabepfad, index=False)
|
||||
|
||||
def main():
|
||||
"""Hauptfunktion, die die Datenverarbeitung steuert."""
|
||||
eingabedatei = 'data/raw/data.csv'
|
||||
ausgabedatei = 'data/processed/bereinigte_daten.csv'
|
||||
|
||||
daten = lade_daten(eingabedatei)
|
||||
bereinigte_daten = bereinige_daten(daten)
|
||||
speichere_daten(bereinigte_daten, ausgabedatei)
|
||||
|
||||
print("Datenverarbeitung abgeschlossen.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
## Zusätzliche Tipps
|
||||
|
||||
- **Kommentiere deinen Code:** Verwende Kommentare, um nicht offensichtliche Teile deines Codes zu erklären. Strebe jedoch danach, Code zu schreiben, der selbsterklärend ist.
|
||||
- **Befolge die PEP 8-Richtlinien:** Halte dich an den [PEP 8](https://www.python.org/dev/peps/pep-0008/)-Styleguide für Python-Code, um die Lesbarkeit zu verbessern. Um dies zu erleichtern, verwende einen Auto-Formatter wie `black` oder `ruff`.
|
||||
- **Verwende aussagekräftige Variablen-, Funktions- und Klassennamen:** Wähle Namen, die ihren Zweck vermitteln. Vermeide Ein-Buchstaben-Variablennamen, außer für einfache Iteratoren. Statt `x` und `y` verwende z. B. `zeit` und `signal`.
|
||||
- **Behandle Ausnahmen:** Verwende try-except-Blöcke, um potenzielle Fehler elegant zu handhaben.
|
||||
|
||||
```python
|
||||
try:
|
||||
daten = lade_daten(eingabedatei)
|
||||
except FileNotFoundError:
|
||||
print(f"Fehler: Die Datei {eingabedatei} wurde nicht gefunden.")
|
||||
sys.exit(1)
|
||||
```
|
||||
|
||||
- **Verwende Logging anstelle von Print-Anweisungen:** Für größere Skripte solltest du das `logging`-Modul verwenden, um eine bessere Kontrolle über Logging-Level und -Ausgaben zu haben.
|
||||
|
||||
```python
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
logging.info("Datenverarbeitung abgeschlossen.")
|
||||
```
|
||||
|
||||
- **Parameterisiere deine Skripte:** Verwende Kommandozeilenargumente oder eine Konfigurationsdatei, um dein Skript flexibler zu gestalten.
|
||||
|
||||
```python
|
||||
import argparse
|
||||
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description="Daten verarbeiten und bereinigen.")
|
||||
parser.add_argument('--input', required=True, help='Pfad zur Eingabedatei')
|
||||
parser.add_argument('--output', required=True, help='Pfad zur Ausgabedatei')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
daten = lade_daten(args.input)
|
||||
bereinigte_daten = bereinige_daten(daten)
|
||||
speichere_daten(bereinigte_daten, args.output)
|
||||
```
|
||||
|
||||
- **Mache deinen Code modular:** Zerlege dein Skript in mehrere Dateien oder Module für bessere Organisation und Wiederverwendbarkeit. Verschiebe beispielsweise Datenverarbeitungsfunktionen, die in mehreren Skripten verwendet werden, in ein separates Modul namens `datenverarbeitung.py`.
|
||||
|
||||
- **Coding einer Abbildung:** Wenn du eine Abbildung codest, kannst du unserem [Leitfaden zum Codieren einer Abbildung](https://github.com/bendalab/plottools/blob/master/docs/guide.md) folgen. Wenn du die gleichen Prinzipien auf deinen Abbildungscode anwendest, wird es einfacher, ihn zu modifizieren und wiederzuverwenden.
|
||||
|
||||
## Fazit
|
||||
|
||||
Wenn du diese Best Practices befolgst, erstellst du Python-Skripte, die:
|
||||
|
||||
- **Lesbar** sind: Klare Struktur und Benennung machen deinen Code leicht verständlich.
|
||||
- **Wartbar** sind: Kapselung und Modularität vereinfachen Updates und Debugging.
|
||||
- **Wiederverwendbar** sind: Funktionen und Klassen können in anderen Skripten importiert und verwendet werden.
|
||||
- **Robust** sind: Fehlerbehandlung stellt sicher, dass dein Skript unerwartete Situationen handhaben kann.
|
||||
|
||||
Denke daran, dass gute Codingraktiken nicht nur dir das Leben erleichtern, sondern auch anderen helfen, die vielleicht mit deinem Code arbeiten. Die Mühe, die du in das Schreiben sauberer und effektiver Skripte steckst, wird sich langfristig auszahlen.
|
||||
|
||||
Viel Spaß beim Programmieren!
|
@ -1,28 +1,3 @@
|
||||
# Structuring the `/data` Directory
|
||||
# Tips and Tricks for the data directory
|
||||
|
||||
German version: [README_de.md](README_de.md)
|
||||
|
||||
```
|
||||
project-name/
|
||||
├── data/
|
||||
├── raw/ # Original, unmodified data
|
||||
├── processed/ # Data derived from raw data
|
||||
└── models/ # Model weights and outputs (if applicable)
|
||||
```
|
||||
|
||||
## Guidelines
|
||||
|
||||
- **`raw/`**:
|
||||
- Store all original data exactly as collected.
|
||||
- **Do not modify** these files to preserve data integrity.
|
||||
- Include metadata or use clear filenames with dates to indicate when the data was recorded.
|
||||
|
||||
- **`processed/`**:
|
||||
- Place cleaned or transformed data here.
|
||||
- Generate these files using scripts.
|
||||
- Document processing steps if necessary.
|
||||
|
||||
- **`models/`** (if you are training models):
|
||||
- Save model weights, checkpoints, and outputs.
|
||||
- Organize by experiment or model version if needed.
|
||||
- Include metadata about training parameters or results.
|
||||
The filename should contain information about the date
|
||||
|
@ -1,26 +0,0 @@
|
||||
# Strukturierung des `/data`-Verzeichnisses
|
||||
|
||||
```
|
||||
project-name/
|
||||
├── data/
|
||||
├── raw/ # Originale, unveränderte Daten
|
||||
├── processed/ # Aus Rohdaten abgeleitete Daten
|
||||
└── models/ # Modellgewichte und Ausgaben (optional)
|
||||
```
|
||||
|
||||
## Richtlinien
|
||||
|
||||
- **`raw/`**:
|
||||
- Speichere alle originalen Daten genau so, wie sie gesammelt wurden.
|
||||
- **Verändere diese Dateien nicht**, um die Datenintegrität zu bewahren.
|
||||
- Füge Metadaten hinzu oder verwende klare Dateinamen mit Datumsangaben, um anzugeben, wann die Daten aufgezeichnet wurden.
|
||||
|
||||
- **`processed/`**:
|
||||
- Lege hier bereinigte oder transformierte Daten ab.
|
||||
- Erstelle diese Dateien mithilfe von Skripten.
|
||||
- Dokumentiere bei Bedarf die Verarbeitungsschritte.
|
||||
|
||||
- **`models/`** (falls du machine learning verwendest):
|
||||
- Speichere Modellgewichte, Checkpoints und Ausgaben.
|
||||
- Organisiere nach Experiment oder Modellversion, falls erforderlich.
|
||||
- Füge Metadaten über Trainingsparameter oder Ergebnisse hinzu.
|
Loading…
Reference in New Issue
Block a user