![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python基础
focus_reality
学习一门编程语言,将结构设计仿真与语言结合起来
展开
-
python字符串
print('dataquest'.startswith('Data')) # Falseprint('dataquest'.startswith('data')) # Trueprint('dataquest'.upper().startswith('DATA')) # True原创 2019-05-18 23:48:44 · 106 阅读 · 0 评论 -
random module
seed(): sets the random seed, so that your results are the reproducible between simulations. As an argument, it takes an integer of your choosing. If you call the function, no output will be genera...翻译 2019-05-22 21:27:55 · 111 阅读 · 0 评论 -
random walk
# Numpy is imported, seed is setimport numpy as npnp.random.seed(123)# Initialize random_walkrandom_walk = [0]# Complete the ___for x in range(100) : # Set step: last element in random_walk...翻译 2019-05-22 22:35:12 · 1087 阅读 · 0 评论 -
列表解析
列表解析结构[expression for target1 in iterable1 [if condition1] for target2 in iterable2 [if condition2]... for targetN in iterableN [if conditionN]]例如res = []for x in range(5): if x % 2 == ...转载 2019-05-18 00:20:58 · 293 阅读 · 0 评论 -
函数式编程工具:map, filter和reduce
1. map将一个函数映射到一个输入列表的所有元素上map(function_to_apply, list_of_inputs) # 结构list(map((lambda x: x + 3), [1, 2, 3, 4])) # [4, 5, 6, 7]list(map(pow, [1, 2, 3], [2, 3, 4])) # 1 ** 2, 2 ** 3, 3 ** 42. filt...原创 2019-05-18 00:59:05 · 182 阅读 · 0 评论 -
Importing data from the Internet
# Import packagefrom urllib.request import urlretrieve# Import pandasimport pandas as pd# Assign url of file: urlurl = 'https://s3.amazonaws.com/assets.datacamp.com/production/course_1606/datas...转载 2019-05-27 20:52:20 · 198 阅读 · 0 评论 -
python datetime模块日期与时间的处理
Python has three standard modules that are designed to help working with dates and times:The calendar moduleThe time moduleThe datetime moduleimport datetime as dtibm_founded = dt.datetime(1911...转载 2019-05-18 19:06:42 · 676 阅读 · 0 评论 -
Jupyter Notebook
%history -p # 查看历史记录openfile = open(r'C:\Users\cheng\Desktop\test.txt') # 读取文件原创 2019-05-18 19:25:22 · 129 阅读 · 0 评论 -
using tuples to return multiple values
# Define shout_all with parameters word1 and word2def shout_all(word1, word2): # Concatenate word1 with '!!!': shout1 shout1 = word1 + '!!!' # Concatenate word2 with '!!!': shou...翻译 2019-05-23 19:26:55 · 163 阅读 · 0 评论 -
default and flexable arguments
Functions with one default argument# Define shout_echodef shout_echo(word1, echo = 1): """Concatenate echo copies of word1 and three exclamation marks at the end of the string.""" # Co...翻译 2019-05-23 20:50:01 · 108 阅读 · 0 评论 -
sql
Querying relational databases in Python# Import necessary modulefrom sqlalchemy import create_engine# Create engine: engineengine = create_engine('sqlite:///Chinook.sqlite')# Save the table nam...转载 2019-05-26 22:46:18 · 146 阅读 · 0 评论 -
Importing Data in Python: Importing data from other file types
import oswd = os.getcwd()os.listdir(wd)## loading a pickle file# Import pickle packageimport pickle# Open pickle file and load data: dwith open('data.pkl', 'rb') as file: d = pickle.load(...翻译 2019-05-26 14:55:12 · 210 阅读 · 0 评论 -
list
The ; sign is used to place commands on the same line. The following two code chunks are equivalent:# Same linecommand1; command2# Separate linescommand1command2help(). In IPython specif...转载 2019-05-19 23:05:18 · 100 阅读 · 0 评论 -
Numpy
转载 2019-05-20 19:37:36 · 103 阅读 · 0 评论 -
matplotlib
# line plotimport matplotlib.pyplot as pltplt.plot(x,y)plt.show()# Import packageimport matplotlib.pyplot as plt# scatter plotplt.scatter(x,y)# Put the x-axis on a logarithmic scaleplt.xscal...翻译 2019-05-20 23:07:04 · 228 阅读 · 0 评论 -
dict
# Definition of dictionaryeurope = {'spain':'madrid', 'france':'paris', 'germany':'berlin', 'norway':'oslo' }# Print out the keys in europeprint(europe.keys())# Print out value that belongs to key...翻译 2019-05-20 23:25:46 · 136 阅读 · 0 评论 -
Introduction to iterators
翻译 2019-05-24 19:56:52 · 101 阅读 · 0 评论 -
enumerate and zip
enumerate() returns an enumerate object that produces a sequence of tuples, and each of the tuples is an index-value pair.# Create a list of strings: mutantsmutants = ['charles xavier', ...转载 2019-05-24 21:31:03 · 282 阅读 · 0 评论 -
pndas DataFrame
import pandas as pd# Build cars DataFramenames = ['United States', 'Australia', 'Japan', 'India', 'Russia', 'Morocco', 'Egypt']dr = [True, False, False, False, True, True, True]cpc = [809, 731, 5...翻译 2019-05-21 21:59:47 · 202 阅读 · 0 评论 -
数组比较
# Create arraysimport numpy as npmy_house = np.array([18.0, 20.0, 10.75, 9.50])your_house = np.array([14.0, 24.0, 14.25, 9.0])# my_house greater than 18.5 or smaller than 10print(np.logical_or(m...翻译 2019-05-21 23:18:12 · 370 阅读 · 0 评论 -
Importing data in python: Introducton and flat fils
1. Introduction and flat files1.1 importing entire text files# Open a file: filefile = open('moby_dick.txt', mode = 'r')# Print itprint(file.read())# Check whether file is closed using closed...翻译 2019-05-26 13:19:52 · 203 阅读 · 0 评论 -
error handing
# Define shout_echodef shout_echo(word1, echo=1): """Concatenate echo copies of word1 and three exclamation marks at the end of the string.""" # Initialize empty strings: echo_word, shou...翻译 2019-05-23 21:34:42 · 296 阅读 · 0 评论