栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Coursera-Introduction to Data Science in Python-Day 1

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Coursera-Introduction to Data Science in Python-Day 1


Week 1: Introduction to the Course

Table of Contents

Week 1: Introduction to the Course

1. Python Types and Sequences

Python Types (tuple, list, dictionary)SlicingSplit Stringsdictionary visittuple assigned to variable 2. More on Strings3. Reading and Writing CSV files4. Python Dates and Times5. Advanced Python Objects, map()

map() 6. Advanced Python Lambda and List Comprehensions Week1: Fundamentals of Data Manipulation

Numerial Python Library(NumPy)

Array Operations Summary

1. Python Types and Sequences Python Types (tuple, list, dictionary)

Tuple
x = (1, 'a', 2, 'b')
不可更改,数据类型不必一致。List
x = [1, 'a', 2,'b']
可以更改,数据类型不必一致。
更改方式:

x.append(3,3)
print(x)
for item in x:
	print(item)
i = 0
while i!=len(x):
	print(x[i])
	i = i+1
1 in[1,2,3]
#Out: True

dictionary Slicing

x = 'This is a string'
print(x[0])
print(x[0:1]) #包括前面,不包括后面
print(x[0,2])

x[-1]# 倒数第一个元素
x[-4:-2] #倒数第四,倒数第三
x[:3] #前三个元素
x[3:] #从第三个到随后一个元素
Split Strings
firstname = 'Christopher'
lastname = 'Brooks'

print(firstname + ' ' + lastname)
print(firstname *3)
print('Chris' in firstname)
firstname = 'Christopher Brthur Haseen Brooks'. split(' ')[0]
lastname = 'Christopher Brthur Haseen Brooks'. split(' ')[-1]
print(firstname)
print(lastname)
'Chris' + str(2)
#out: Chris2
x ={'Grace Wang': 'ruowenwang@yeah.net', 'Bill Gates': 'bill@microsoft.com'}
x['Grace Wang']
#out: ruowenwang@yeah.net
dictionary visit
for name in x:
	print(x[name]) #print key in dictionary

for email in x.values():
	print(email) #print value in dictionary

for name, email in x.items():
	print(name)
	print(email)
tuple assigned to variable
x = ('Christopher', 'Brooks', 'brooksch@coursera.edu')
fname, lname, email = x

fname 
# out: 'Christopher'
lname 
# out: 'Brooks'
email
# out: 'brooksch@coursera.edu'

2. More on Strings
sales_record = {'price':3.24, 'num_items': 4, 'person': 'Chris'}

sales_statement = '{} bought {} item(s) at a price of {} each for a total of {}'

print(sales_satement.format(sales_record['person'], sales_record['num_items'], sales_record['price'], sales_record['num_items']*sales_record['price']
3. Reading and Writing CSV files
import csv

%precision 2

with open('npg.csv)as csvfile
	npg = list(csv.DictReader(csvfile))


Waiting to be Updated

4. Python Dates and Times
import dateime as dt
import time as tm

tm.time()
dtnow = dt.datetime.fromtimestamp(tm.time())
dtnow
dtnow.year, dtnow.month, dtnow.hour, dtnow.minute, dtnow.second

delta = dt.timedelta(days = 100)
delta
today = dt.date.today()

today-delta

today>today-delta
5. Advanced Python Objects, map()

Objects

class Person
	department ='school of Information'
	def set_name(self, new_name):
		self.name = new_name
	def sef_locatoin(self, new_location):
		self.location = new_location
map()
store1 = [10.00,11.00,12.34,2.34]
store2 = [9..00,11.10,12.34,2.01]
cheapest = map(min, store1, store2)
cheapest
6. Advanced Python Lambda and List Comprehensions
my_fuction = lambda a, b,c: a+b
my_fuction(1,2,3)
my_list =[]
for number in range(0,1000):
	if number %2 ==0:
		my_list.append(number)
my_list

##list comrepension:
my_list = [number for number in range(0, 1000) if number %2 ==0]
Week1: Fundamentals of Data Manipulation Numerial Python Library(NumPy)

creating array with certain data typemanipulating arrayselecting elements from arraysloading dataset into array

import numpy as np
import math

a = np.array([1,2,3])
print(a)
print(a.ndim)
b = np.array([[1,2,3],[4,5,6]])
b.ndim #out: 2
b.shape # length of each dimension
#out: (2,3)
b.dtype
c = np.array([2.2,5,1.1])
c.dtype.name
d = np.zeros((2,3)
print(d)

e = np.ones((2,3))

np.random.rand(2,3)
f = np.range (10, 50,2)
f
np.linspace (0,2, 15) # 15 numbers form 0 (inclusive) to 2 (inclusive)
Array Operations
a = np.array ([10,20,30,40])
b = np.array ([1,2,3,4])

c = a-b
d = a*b

Summary

碎碎念:本来计划今天学完第一周的内容, 没有料到后面有点多,没有学完。想要一个月内学完Applied Data Science with Python Specialization的四门课程,也就是每周一门,理论上可行。花了300+人民币,希望按时完成学习任务。

今天的学习内容比较基础,主要有几点需要注意⚠️:

    tuple 和list的特点Reading and writing CSV files 内容太多太快,没有跟上,以后补充。map() 不够熟悉lambda函数不够熟悉Fundamentals of data maniputation 明日完成

summary date: March 5, 2022


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/754765.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号