- 博客(34)
- 收藏
- 关注
原创 linux学习01
### repeat commandshistory :: 打印命令行历史!6 :: 重新运行命令历史的第6条命令head -n 5 seasonal/summer.csv::打印seasonal/summer.csv前5行
2019-06-24 19:31:27
138
转载 Performing HTTP requests in Python using urllib
Performing HTTP requests in Python using urllib# Import packagesfrom urllib.request import urlopen, Request# Specify the urlurl = "http://www.datacamp.com/teach/documentation"# This packages th...
2019-05-27 22:16:23
171
转载 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
262
转载 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
193
翻译 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
243
翻译 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
259
翻译 advanve comprehesions
list comprehensions# Create a 5 x 5 matrix using a list of lists: matrixmatrix = [[col for col in range(5)] for row in range(5)]# Print the matrixfor row in matrix: print(row)[0, 1, 2, 3, ...
2019-05-24 22:10:54
176
转载 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
341
翻译 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
344
翻译 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
145
翻译 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
206
翻译 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
1147
翻译 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
142
翻译 数组比较
# 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
404
翻译 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
248
翻译 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
170
翻译 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
260
转载 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
135
原创 python字符串
print('dataquest'.startswith('Data')) # Falseprint('dataquest'.startswith('data')) # Trueprint('dataquest'.upper().startswith('DATA')) # True
2019-05-18 23:48:44
137
原创 Jupyter Notebook
%history -p # 查看历史记录openfile = open(r'C:\Users\cheng\Desktop\test.txt') # 读取文件
2019-05-18 19:25:22
158
转载 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
725
原创 函数式编程工具: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
247
转载 列表解析
列表解析结构[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
319
转载 import导入的几种方式
1. Import the whole module by name2. Import definitions via name or wildcard3.Import whole module by alias
2019-05-17 23:48:59
2081
原创 读取csv文件转换为列表序列
from csv import readerpotus = list(reader(open(‘potus_visitors_2015.csv’)))
2019-05-17 21:51:09
4543
2
转载 Class
An object is an entity that stores data.An object’s class defines specific properties objects of that class will have.
2019-05-16 22:07:52
127
转载 apply formatting to numbers using str.format()

2019-05-16 21:11:14
260
转载 str.format() method
字符串输出name = "Kylie"num = 8output = name + "'s favorite number is " + str(num)print(output)Kylie’s favorite number is 8str.format() method 输出1. The variables are inserted into the {} by the or...
2019-05-16 20:45:17
237
转载 frequence table
fruit = ['orange', 'orange', 'orange', 'banana', 'apple', 'banana', 'orange', 'banana', 'apple', 'banana'] fruit_frequency = {}for f in fruit: if f not in fruit_freque...
2019-05-16 20:31:08
208
转载 Count the number of Duplicates
Count the number of DuplicatesWrite a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The inpu...
2019-04-26 22:50:56
360
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人