从零开始的python基础教程(3)

十、Popular Python Packages

从零开始的python基础教程(3)_第1张图片

1、What are APIs

Application Programming Interface

2、Search for Business

在这里插入图片描述

从零开始的python基础教程(3)_第2张图片

从零开始的python基础教程(3)_第3张图片

3、Hiding API Keys

从零开始的python基础教程(3)_第4张图片

从零开始的python基础教程(3)_第5张图片

so now when we push our codes to Github repository, our config file will not be there

十一、使用Dyjango构建Web应用程序

1、Your First Django Project

在这里插入图片描述
从零开始的python基础教程(3)_第6张图片
then the virtual environment for this project is activated(虽然好像没用
在这里插入图片描述
从零开始的python基础教程(3)_第7张图片
从零开始的python基础教程(3)_第8张图片
从零开始的python基础教程(3)_第9张图片

2、Creating an App

续上节ctrl-c
在这里插入图片描述
从零开始的python基础教程(3)_第10张图片

3、Views

Index represents the main page of an app

在movies/view.py:

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.


def index(request):
    return HttpResponse("Hello World")

movies下创建一个urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index')
]

在vidly下的urls.py中修改加上,变为:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('movies/', include('movies.urls'))
]

再次
在这里插入图片描述
从零开始的python基础教程(3)_第11张图片
这时你会惊奇的发现:
从零开始的python基础教程(3)_第12张图片

4、Models

在movies/models.py:

from django.db import models


class Genre(models.Model):
    name = models.CharField(max_length=255)


class Movie(models.Model):
    title = models.CharField(max_length=255)
    release_year = models.IntegerField()
    number_in_stock = models.IntegerField()
    daily_rate = models.FloatField()
    genre = models.ForeignKey(Genre, on_delete=models.CASCADE())

5、Migrations

看到项目目录下的db.sqlite3

在SQLite下打开数据库,打开项目中的这个sqlite3
从零开始的python基础教程(3)_第13张图片

Everytime we create new model classes or modify existing ones, we tell django to compare our model classes with our database, and based on that it would create a migration

A migration is essentially a python file, that includes some code let me run that it will synchronize our database with our model classes
在这里插入图片描述
no changes are detected because by default Django is not aware of our model classes
So the first step is to register movies app with Django, let me show you how to do that

vidly/settings.py
修改部分成为:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'movies.apps.MoviesConfig'
]

十二、使用Python进行机器学习

1、Machine Learning in Action

从零开始的python基础教程(3)_第14张图片

2、Libraries and Tools

LIBRARIES: Numpy, Pandas, MatPlotLib, Scikit-Learn

Numpy which provides a multi-dimensional array

Pandas which of the data analysis library that provide a concept called dataframe,
A dataframe is a two dimentsional data structure similar to an Excel spreadsheet, so we have rows and columns

MatPlotLib is a two dimensional plotting library for creating graphs on plots

Scikit-Learn provides all these common algorithms

1、安装Anaconda

2、安装jupyter
pip install notebook

3、启动
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
进入Desktop文件夹下,从零开始的python基础教程(3)_第15张图片
新建后重命名为HelloWorld
在这里插入图片描述

3、Importing a Data Set

kaggle
中搜索video game sales
从零开始的python基础教程(3)_第16张图片
可以看到要下载的是vgsales.csv,其中有11列
点击下载,然后将下载好的csv文件放在和刚才ipynb文件同一目录下

从零开始的python基础教程(3)_第17张图片
从零开始的python基础教程(3)_第18张图片

4、Jupyter Shortcuts

选中是绿色「编辑模式」,再按一下esc,会变成蓝色「命令模式」
按a在选中的上面添加一行,按b在选中的下面添加一行,按两次d删除一行
从零开始的python基础教程(3)_第19张图片
df.然后按tab可以出现自动提示,对象中所有的属性和方法

cursor在方法名上然后按shift和tab可以看到提示:
从零开始的python基础教程(3)_第20张图片
cmd + / 注释

5、A Real Problem

下载music.csv
从零开始的python基础教程(3)_第21张图片

6、Preparing the Data

从零开始的python基础教程(3)_第22张图片
从零开始的python基础教程(3)_第23张图片

7、Learning and Predicting

从零开始的python基础教程(3)_第24张图片

你可能感兴趣的:(python,django,开发语言)