u1s1,这门课的assignment还是有点难度的,特别是assigment4(哀怨),放给大家参考啦~
   有时间(需求)就把所有代码放到github上(好担心被河蟹啊)
   先放下该课程相关链接:
   Coursera | Introduction to Data Science in Python(University of Michigan)| quiz答案
   Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment1
   Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment2
   Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment3
   Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment4
   嘿,顺便推广下自己的博客,以后CSDN的文章都会放到自己的博客的。

Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment1

  • Assignment 1
    • Part A
      • Code
      • 结果
    • Part B
      • Code
      • 结果
    • Part C
      • Code
      • 结果

assignment1挺简单的,就是个入门。

Assignment 1

For this assignment you are welcomed to use other regex resources such a regex “cheat sheets” you find on the web.

Before start working on the problems, here is a small example to help you understand how to write your own answers. In short, the solution should be written within the function body given, and the final result should be returned. Then the autograder will try to call the function and validate your returned result accordingly.

def example_word_count():# This example question requires counting words in the example_string below.example_string = "Amy is 5 years old"# YOUR CODE HERE.# You should write your solution here, and return your result, you can comment out or delete the# NotImplementedError below.result = example_string.split(" ")return len(result)#raise NotImplementedError()

Part A

Find a list of all of the names in the following string using regex.

Code

import re
def names():simple_string = """Amy is 5 years old, and her sister Mary is 2 years old. Ruth and Peter, their parents, have 3 kids."""# YOUR CODE HERE
#     raise NotImplementedError()pattern = "[A-Z][a-z]*"return re.findall(pattern, simple_string)
assert len(names()) == 4, "There are four names in the simple_string"

结果

Part B

The dataset file in assets/grades.txt contains a line separated list of people with their grade in
a class. Create a regex to generate a list of just those students who received a B in the course.

Code

import re
def grades():with open ("assets/grades.txt", "r") as file:grades = file.read()# YOUR CODE HERE
#     raise NotImplementedError()pattern = "[\w ]*:\ B"return re.findall(pattern, grades)

   下面这个也可以。其实都可以,两个的区别是是否包含成绩。

def grades():with open ("assets/grades.txt", "r") as file:grades = file.read()# YOUR CODE HERE
#     raise NotImplementedError()pattern = "[\w]*\ [\w]*(?=:\ B)"return re.findall(pattern, grades)
assert len(grades()) == 16

结果

   包含成绩:

   不包含成绩:

Part C

Consider the standard web log file in assets/logdata.txt. This file records the access a user makes when visiting a web page (like this one!). Each line of the log has the following items:

  • a host (e.g., ‘146.204.224.152’)
  • a user_name (e.g., ‘feest6811’ note: sometimes the user name is missing! In this case, use ‘-’ as the value for the username.)
  • the time a request was made (e.g., ‘21/Jun/2019:15:45:24 -0700’)
  • the post request type (e.g., ‘POST /incentivize HTTP/1.1’ note: not everything is a POST!)

Your task is to convert this into a list of dictionaries, where each dictionary looks like the following:

example_dict = {"host":"146.204.224.152", "user_name":"feest6811", "time":"21/Jun/2019:15:45:24 -0700","request":"POST /incentivize HTTP/1.1"}

Code

import re
def logs():with open("assets/logdata.txt", "r") as file:logdata = file.read()# YOUR CODE HERE
#     raise NotImplementedError()pattern = """(?P<host>[\d]*.[\d]*.[\d]*.[\d]*)    (\ -\ )  (?P<user_name>[\w-]*) (\ \[) (?P<time>\w*/\w*/.*)(\]\ \") (?P<request>.*)(")"""# YOUR CODE HEREresult = []for item in re.finditer(pattern, logdata, re.VERBOSE):result.append(item.groupdict())return result
assert len(logs()) == 979one_item={'host': '146.204.224.152','user_name': 'feest6811','time': '21/Jun/2019:15:45:24 -0700','request': 'POST /incentivize HTTP/1.1'}
assert one_item in logs(), "Sorry, this item should be in the log results, check your formating"

结果

  部分:

   大家其他还有需要的就在评论留言哦

Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment1相关推荐

  1. Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment2

       u1s1,这门课的assignment还是有点难度的,特别是assigment4(哀怨),放给大家参考啦~    有时间(需求)就把所有代码放到github上(好担心被河蟹啊)    先放下该课 ...

  2. Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment4

       u1s1,这门课的assignment还是有点难度的,特别是assigment4(哀怨),放给大家参考啦~    有时间(需求)就把所有代码放到github上(好担心被河蟹啊)    先放下该课 ...

  3. Coursera | Introduction to Data Science in Python(University of Michigan)| Assignment3

       u1s1,这门课的assignment还是有点难度的,特别是assigment4(哀怨),放给大家参考啦~    有时间(需求)就把所有代码放到github上(好担心被河蟹啊)    先放下该课 ...

  4. 【DS实践 | Coursera】Assignment3 | Introduction to Data Science in Python

    文章目录 前言 一.Q1 二.Q2 三.Q3 四.Q4 五.Q5 六.Q6 七.Q7 八.Q8 九.Q9 十.Q10 十一.Q11 十二.Q12 十三.Q13 前言 本章是Introduction t ...

  5. Coursera | Applied Plotting, Charting Data Representation in Python(UMich)| Assignment2

       所有assignment相关链接:   Coursera | Applied Plotting, Charting & Data Representation in Python(Uni ...

  6. Coursera | Applied Plotting, Charting Data Representation in Python(UMich)| Assignment4

       所有assignment相关链接:   Coursera | Applied Plotting, Charting & Data Representation in Python(Uni ...

  7. Coursera | Applied Plotting, Charting Data Representation in Python(UMich)| W3 Practice Assignment

       所有assignment相关链接:   Coursera | Applied Plotting, Charting & Data Representation in Python(Uni ...

  8. Coursera | Applied Data Science with Python 专项课程 | Applied Machine Learning in Python

    本文为学习笔记,记录了由University of Michigan推出的Coursera专项课程--Applied Data Science with Python中Course Three: Ap ...

  9. Coursera | Introduction to Data Analytics(IBM) | Quiz答案

    其他链接: 假装有笔记(有时间写出来) Coursera | Introduction to Data Analytics(IBM) | Final Assignment: Data Analysis ...

最新文章

  1. 根据基因或者蛋白的id提取序列---extract_seq.exe
  2. 计算最大回撤_看专业分析研究员如何一步步解读外汇市场结构,实现交易最大化盈利化!...
  3. [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platfor
  4. 20190718考试70分记
  5. Microsoft AI - Custom Vision in C#
  6. css3 多列布局使用
  7. python读取文件乱码
  8. web 开发一个能进行人员管理(查询,删除,添加)的应用
  9. 操作系统的概念,功能和目标
  10. json爬虫获取列表数据不全,已解决
  11. 解决mysql闪退问题
  12. 【Matlab绘图进阶第2弹】Matlab绘制论文柱状图
  13. 多元线性模型的分位数回归
  14. 将py文件打包成可exe文件
  15. 基于WEB在线音乐工厂的设计与实现
  16. 周志华机器学习--绪论
  17. 关于清理C盘、更改文件路径、扩大磁盘空间的相关方法
  18. Bloom Filter 和 Count-Min Sketch 介绍
  19. 在Pycharm set ops_config=local之后,直接echo %ops_config%能找到ops_config,但是输入print(os.environ)里边没有ops_config
  20. 知名站长工具服务商:爱站网突然关站

热门文章

  1. 用Wireshark抓包分析协议 计算机网络
  2. 心跳包(确保连接的有效性)
  3. bash alias命令03
  4. linux打包解压命令
  5. 不知道PDF转PPT转换器哪个好用?分享三个简单好用的办公用具
  6. 学术诚信的重要性_宋瑞:坚持学术诚信 恪守学术道德 捍卫学术尊严
  7. laravel 手动创建分页器LengthAwarePaginator
  8. 【jquery】jquery-icheck radio的点击事件、change事件、获取当前选中的值
  9. CMD命令行下如何切换路径
  10. ReXNet学习笔记 --- ReXNet: Diminishing Representational Bottleneck on Convolutional Neural Network