{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d4780070",
   "metadata": {},
   "source": [
    "# df008_createDataSetFromScratch\n",
    "Create data from scratch with RDataFrame.\n",
    "\n",
    "This tutorial shows how to create a dataset from scratch with RDataFrame\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:** Danilo Piparo (CERN)  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Tuesday, May 19, 2026 at 08:09 PM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3a229838",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:09:34.709959Z",
     "iopub.status.busy": "2026-05-19T20:09:34.709799Z",
     "iopub.status.idle": "2026-05-19T20:09:35.725260Z",
     "shell.execute_reply": "2026-05-19T20:09:35.721414Z"
    }
   },
   "outputs": [],
   "source": [
    "import ROOT"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c165673f",
   "metadata": {},
   "source": [
    "We create an empty data frame of 100 entries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "159a8700",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:09:35.727010Z",
     "iopub.status.busy": "2026-05-19T20:09:35.726863Z",
     "iopub.status.idle": "2026-05-19T20:09:36.208395Z",
     "shell.execute_reply": "2026-05-19T20:09:36.207421Z"
    }
   },
   "outputs": [],
   "source": [
    "df = ROOT.RDataFrame(100)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c965e3a",
   "metadata": {},
   "source": [
    "We now fill it with random numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "240965b8",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:09:36.209934Z",
     "iopub.status.busy": "2026-05-19T20:09:36.209795Z",
     "iopub.status.idle": "2026-05-19T20:09:36.357172Z",
     "shell.execute_reply": "2026-05-19T20:09:36.356207Z"
    }
   },
   "outputs": [],
   "source": [
    "ROOT.gRandom.SetSeed(1)\n",
    "df_1 = df.Define(\"rnd\", \"gRandom->Gaus()\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a7a6f9c",
   "metadata": {},
   "source": [
    "And we write out the dataset on disk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d56e1ef6",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:09:36.358634Z",
     "iopub.status.busy": "2026-05-19T20:09:36.358499Z",
     "iopub.status.idle": "2026-05-19T20:09:37.586197Z",
     "shell.execute_reply": "2026-05-19T20:09:37.585782Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<cppyy.gbl.ROOT.RDF.RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager> > object at 0x564bd2e96cb0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_1.Snapshot(\"randomNumbers\", \"df008_createDataSetFromScratch_py.root\")"
   ]
  }
 ],
 "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.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
