[PYTHON] VS-Codefragmente für Datenanalysten

zunaechst

Wenn ich täglich Code schreibe, schreibe oder suche ich oft immer wieder nach demselben Inhalt. Wenn Sie in einem solchen Fall ein Snippet registrieren, können Sie es mit weniger Aufwand eingeben, und die Codierung ist schneller. Dieses Mal werde ich Snippets vorstellen, die bei der Analyse von Daten nützlich sind.

Einstellmethode

Im Folgenden erfahren Sie, wie Sie ein Snippet mit VS-Code registrieren.

Inhalt

Erstellen Sie Snippets für die folgenden Bibliotheken.

snippets/python.json

snippets/python.json


{
    "lgb": {
        "prefix": [
            "lgb",
            "import lightgbm as lgb"
        ],
        "body": "import lightgbm as lgb",
        "description": "Import LightGBM"
    },
    "np": {
        "prefix": [
            "np",
            "import numpy as np"
        ],
        "body": "import numpy as np",
        "description": "Import Numpy"
    },
    "pd": {
        "prefix": [
            "pd",
            "import pandas as pd"
        ],
        "body": "import pandas as pd",
        "description": "Import Pandas"
    },
    "plt": {
        "prefix": [
            "plt",
            "import matplotlib.pyplot as plt",
            "from matplotlib import ..."
        ],
        "body": "from matplotlib import pyplot as plt",
        "description": "Import Matplotlib"
    },
    "sns": {
        "prefix": [
            "sns",
            "import seaborn as sns"
        ],
        "body": "import seaborn as sns",
        "description": "Import seaborn"
    },
    "joblib.dump": {
        "prefix": [
            "joblib.dump",
            "from joblib import dump"
        ],
        "body": "from joblib import dump",
        "description": "Import `dump` in Joblib"
    },
    "joblib.load": {
        "prefix": [
            "joblib.load",
            "from joblib import load"
        ],
        "body": "from joblib import load",
        "description": "Import `load` in Joblib"
    },
    "sklearn.compose.make_column_transformer": {
        "prefix": [
            "sklearn.compose.make_column_transformer",
            "from sklearn.compose import ..."
        ],
        "body": "from sklearn.compose import make_column_transformer",
        "description": "Import `make_column_transformer` in scikit-learn"
    },
    "sklearn.datasets.load_*": {
        "prefix": [
            "sklearn.datasets.load_*",
            "from sklearn.datasets import ..."
        ],
        "body": "from sklearn.datasets import ${1:load_iris}",
        "description": "Import a function that loads a dataset"
    },
    "sklearn.pipeline.make_pipeline": {
        "prefix": [
            "sklearn.pipeline.make_pipeline",
            "from sklearn.pipeline import ..."
        ],
        "body": "from sklearn.pipeline import make_pipeline",
        "description": "Import `make_pipeline` in scikit-learn"
    },
    "logger = ...": {
        "prefix": "logger = ...",
        "body": "logger = logging.getLogger(${1:__name__})",
        "description": "Get a logger"
    },
    "dtrain = ...": {
        "prefix": "dtrain = ...",
        "body": "dtrain = lgb.Dataset(${1:X}, label=${2:y})",
        "description": "Create a LightGBM dataset instance"
    },
    "booster = ...": {
        "prefix": "booster = ...",
        "body": [
            "booster = lgb.train(",
            "\t${1:params},",
            "\t${2:dtrain},",
            "\t${3:# **kwargs}",
            ")"
        ],
        "description": "Train a LightGBM booster"
    },
    "ax = ...": {
        "prefix": "ax = ...",
        "body": [
            "ax = lgb.plot_importance(",
            "\t${1:booster},",
            "\t${2:# **kwargs}",
            ")"
        ],
        "description": "Plot feature importances"
    },
    "f, ax = ...": {
        "prefix": "f, ax = ...",
        "body": "f, ax = plt.subplots(figsize=${1:(8, 6)})",
        "description": "Create a figure and a set of subplots"
    },
    "df = ...": {
        "prefix": "df = ...",
        "body": [
            "df = pd.read_csv(",
            "\t${1:filepath_or_buffer},",
            "\t${2:# **kwargs}",
            ")"
        ],
        "description": "Read a csv file into a Pandas dataFrame"
    },
    "description = ...": {
        "prefix": "description = ...",
        "body": "description = ${1:df}.describe(include=${2:\"all\"})",
        "description": "Create a Pandas dataframe description"
    },
    "with pd.option_context(...": {
        "prefix": "with pd.option_context(...",
        "body": [
            "with.pd.option_context(",
            "\t\"display.max_rows\",",
            "\t${1:None},",
            "\t\"display.max_columns\",",
            "\t${2:None},",
            "):",
            "\tdisplay(${3:pass})"
        ],
        "description": "Set temporarily Pandas options"
    },
    "X, y = ...": {
        "prefix": "X, y = ...",
        "body": "X, y = ${1:load_iris}(return_X_y=True)",
        "description": "Load and return the dataset"
    },
    "X_train, X_test, ...": {
        "prefix": "X_train, X_test, ...",
        "body": [
            "X_train, X_test, y_train, y_test = train_test_split(",
            "\tX,",
            "\ty,",
            "\trandom_state=${1:0},",
            "\tshuffle=${2:True},",
            ")"
        ],
        "description": "Split arrays into train and test subsets"
    },
    "estimator = BaseEstimator(...": {
        "prefix": "estimator = BaseEstimator(...",
        "body": [
            "estimator = ${1:BaseEstimator}(",
            "\t${2:# **params}",
            ")"
        ],
        "description": "Create an scikit-learn estimator instance"
    },
    "estimator = make_pipeline(...": {
        "prefix": "estimator = make_pipeline(...",
        "body": [
            "estimator = make_pipeline(",
            "\t${1:estimator},",
            "\t${2:# *steps}",
            ")"
        ],
        "description": "Create a scikit-learn pipeline instance"
    },
    "estimator = make_column_transformer(...": {
        "prefix": "estimator = make_column_transformer(...",
        "body": [
            "estimator = make_column_transformer(",
            "\t(${1:estimator}, ${2:columns}),",
            "\t${3:# *transformers}",
            ")"
        ],
        "description": "Create a scikit-learn column transformer instance"
    },
    "estimator.fit(...": {
        "prefix": "estimator.fit(...",
        "body": [
            "${1:estimator}.fit(",
            "\t${2:X},",
            "\ty=${3:y},",
            "\t${4:# **fit_params}",
            ")"
        ],
        "description": "Fit the estimator according to the given training data"
    },
    "dump(...": {
        "prefix": "dump(...",
        "body": "dump(${1:estimator}, ${2:filename}, compress=${3:0})",
        "description": "Save the estimator"
    },
    "estimator = load(...": {
        "prefix": "estimator = load(...",
        "body": "estimator = load(${1:filename})",
        "description": "Load the estimator"
    },
    "y_pred = ...": {
        "prefix": "y_pred = ...",
        "body": "y_pred = ${1:estimator}.predict(${2:X})",
        "description": "Predict using the fitted model"
    },
    "X = ...": {
        "prefix": "X = ...",
        "body": "X = ${1:estimator}.transform(${2:X})",
        "description": "Transform the data"
    }
}

Am Ende

Wenn Sie ein neues Snippet erstellen, werde ich es von Zeit zu Zeit aktualisieren.

Recommended Posts

VS-Codefragmente für Datenanalysten
Mac-Grundeinstellungen (für Datenanalysten)
(Für mich) Setzen Sie den Kolben in den VS-Code ein
VS-Code-Einstellungen
Richten Sie die TinyGo-Entwicklungsumgebung für VS Code ein
Kenntnisse und Studienmethoden für zukünftige Datenanalysten erforderlich
VS-Code-Einstellungen für die Entwicklung in Python mit Abschluss
Techniken zum Testen von Code?
Aktivieren Sie externe Bibliotheksinformationen mit Pipenv + VSCode
Stellen Sie settings.json für eine effiziente Python-Codierung mit VS-Code bereit
Python-Code zum Schreiben von CSV-Daten in den DSX-Objektspeicher
Komfortables LaTeX mit Windows-Subsystem für Linux und VS-Code
Datensatz für maschinelles Lernen
Python mit VSCode (Windows 10)
Python für die Datenanalyse Kapitel 4
Schreiben Sie Spigot in VS Code
Persönliches Python-Code-Memo
Setzen Sie VSCode auf PyCharm.
Testcode zur Bewertung von Dekorateuren
Debuggen Sie Python mit VS-Code
Python verwendete häufig Codefragmente
Python für die Datenanalyse Kapitel 2
[PyTorch] Datenerweiterung zur Segmentierung
[Python] Beispielcode für die Python-Grammatik
Tipps und Vorsichtsmaßnahmen bei der Datenanalyse
Python für die Datenanalyse Kapitel 3
Wettbewerb mit VS-Code Erstellen Sie eine Python-Umgebung für Profis unter Windows