You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Saving data in Python takes syntax of the following form for `.csv` files:
92
91
@@ -104,15 +103,15 @@ For example:
104
103
mydata.to_csv("mydata.csv", index = False)
105
104
```
106
105
107
-
# Set a Seed {#seed}
106
+
# Set a Seed {#sec-seed}
108
107
109
108
Set a seed (any number) to reproduce the results of analyses that involve random number generation.
110
109
111
110
```{python}
112
111
random.seed(52242) # uses the random module
113
112
```
114
113
115
-
# Run a `Python` Script {#runScript}
114
+
# Run a `Python` Script {#sec-runScript}
116
115
117
116
To run a `Python` script, use the following syntax:
118
117
@@ -122,7 +121,7 @@ To run a `Python` script, use the following syntax:
122
121
%run "filepath/filename.py"
123
122
```
124
123
125
-
# Render a Quarto (`.qmd`) File {#renderQmd}
124
+
# Render a Quarto (`.qmd`) File {#sec-renderQmd}
126
125
127
126
To render a Quarto (`.qmd`) file, you would typically use the command line.
128
127
Here is the equivalent command in a `Python` cell using the `!` operator to run shell commands:
@@ -133,15 +132,15 @@ Here is the equivalent command in a `Python` cell using the `!` operator to run
133
132
!quarto render "filepath/filename.qmd"
134
133
```
135
134
136
-
# Variable Names {#varNames}
135
+
# Variable Names {#sec-varNames}
137
136
138
137
To look at the names of variables in a dataframe, use the following syntax:
139
138
140
139
```{python}
141
140
list(mydata.columns)
142
141
```
143
142
144
-
# Logical Operators {#logicalOperators}
143
+
# Logical Operators {#sec-logicalOperators}
145
144
146
145
Logical operators evaluate a condition for each value and yield values of `True` and `False`, corresponding to whether the evaluation for a given value met the condition.
A full outer join includes all rows in $x$ **or** $y$.
511
511
It returns columns from $x$ and $y$.
@@ -518,7 +518,7 @@ print(fullJoinData)
518
518
print(fullJoinData.shape)
519
519
```
520
520
521
-
### Left Outer Join {#leftJoin}
521
+
### Left Outer Join {#sec-leftJoin}
522
522
523
523
A left outer join includes all rows in $x$.
524
524
It returns columns from $x$ and $y$.
@@ -531,7 +531,7 @@ print(leftJoinData)
531
531
print(leftJoinData.shape)
532
532
```
533
533
534
-
### Right Outer Join {#rightJoin}
534
+
### Right Outer Join {#sec-rightJoin}
535
535
536
536
A right outer join includes all rows in $y$.
537
537
It returns columns from $x$ and $y$.
@@ -544,7 +544,7 @@ print(rightJoinData)
544
544
print(rightJoinData.shape)
545
545
```
546
546
547
-
### Inner Join {#innerJoin}
547
+
### Inner Join {#sec-innerJoin}
548
548
549
549
An inner join includes all rows that are in **both** $x$ **and** $y$.
550
550
An inner join will return one row of $x$ for each matching row of $y$, and can duplicate values of records on either side (left or right) if $x$ and $y$ have more than one matching record.
@@ -558,7 +558,7 @@ print(innerJoinData)
558
558
print(innerJoinData.shape)
559
559
```
560
560
561
-
### Cross Join {#crossJoin}
561
+
### Cross Join {#sec-crossJoin}
562
562
563
563
A cross join combines each row in $x$ with each row in $y$.
Copy file name to clipboardExpand all lines: django.qmd
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -20,21 +20,21 @@ format:
20
20
21
21
`Django` uses a Model-View-Controller architecture.
22
22
23
-
### URL Patterns {#urlPatterns}
23
+
### URL Patterns {#sec-urlPatterns}
24
24
25
-
The URL patterns determine which [view](#views) to pass the request to for handling.
25
+
The URL patterns determine which [view](#sec-views) to pass the request to for handling.
26
26
URL patterns are defined in `urls.py`.
27
27
28
-
### Views {#views}
28
+
### Views {#sec-views}
29
29
30
30
Views provide the logic or control flow portion of the project.
31
31
A view is a `Python` callable, such as a function that takes an `HTTP` request as an argument and returns an `HTTP` response for the web server to return.
32
-
Each view we define can leverage [models](#models) and [templates](#templates).
32
+
Each view we define can leverage [models](#sec-models) and [templates](#sec-templates).
33
33
Views are defined in `views.py`.
34
34
35
-
### Models {#models}
35
+
### Models {#sec-models}
36
36
37
-
To perform queries against the database, each [view](#views) can leverage `Django` models as needed.
37
+
To perform queries against the database, each [view](#sec-views) can leverage `Django` models as needed.
38
38
A `Django` model is a class with attributes.
39
39
These model classes provide built-in methods for making queries on the associated database tables.
40
40
Each model is a database table (i.e., spreadsheet).
@@ -43,9 +43,9 @@ Each database record is a row in the spreadsheet
43
43
Models create the data layer of a `Django` app, by defining the schema or underlying structure of a database table.
44
44
Models are defined in `models.py`.
45
45
46
-
#### Defining Fields {#fields}
46
+
#### Defining Fields {#sec-fields}
47
47
48
-
Fields are columns/variables in the database table that are defined by [models](#models).
48
+
Fields are columns/variables in the database table that are defined by [models](#sec-models).
49
49
Field types and field options are provided in the `Django` documentation here: https://docs.djangoproject.com/en/5.0/ref/models/fields/
50
50
51
51
Examples of field types include:
@@ -72,7 +72,7 @@ Common field attributes:
72
72
-`null`: True or False; determines whether a field can be stored as a null (i.e., there is no data for that field in a given record)
73
73
-`choices`: limits the values that can be stored in that field to a set of choices that are provided
74
74
75
-
#### Migrations {#migrations}
75
+
#### Migrations {#sec-migrations}
76
76
77
77
Migrations create the necessary scripts to change the database structure through time as we update our code to change our models.
78
78
@@ -108,7 +108,7 @@ When a migration has been created, but not yet run, we call this an "unapplied m
108
108
This is a common source of errors during development, especially when collaborating with other developers.
109
109
With this in mind, be sure that when working on a team, to coordinate carefully who is changing which model, and to look for new migration files when pulling in code changes.
110
110
111
-
### Templates {#templates}
111
+
### Templates {#sec-templates}
112
112
113
113
Each view we define can also leverage templates, which help with the presentation layer of what the `HTML` response will look like.
114
114
Each template is a separate file that consists of `HTML` along with some extra template syntax for variables, loops, and other control flow.
0 commit comments