def sanitize(time_string):
if '-' in time_string:
splitter = "-"
elif ":" in time_string:
splitter = ":"
else:
return(time_string)
(mins, secs) = time_string.split(splitter)
return (mins+"."+secs)
def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
list_data = data.strip().split(',')
sarah_data = {"name":list_data.pop(0),
"dob":list_data.pop(0),
"times":sorted(set([sanitize(t) for t in list_data]))[0:3]}
return sarah_data
except IOError as ioerr:
print("file error: "+str(ioerr))
return(None)
sarah = get_coach_data("sarah.txt")
print(sarah["name"]+"'s fastest times are: "+str(sarah["times"]))
sarah.txt:
Sarah Sweeney,2002-6-9,2:58,2.58,2:39,2-25,2-55,2:54,2.18,2:55,2:55,2:22,2-21,2.22
string的strip()函数,去除空格,split()分割字符返回列表
set()无序的不重复的集合
sorted()排序算法,返回一个原序列的副本,而原来的序列不发生变化
sort()排序算法,直接改变原来的序列的顺序返回
sort与sorted默认都是升序,有一个reverse的参数,传入true时为逆序
程序中sarah_data为字典数据结构
字典结构定义方式:
sarah_data = {}
sarah_data = dict()
程序中:sorted(set([sanitize(t) for t in list_data]))[0:3]一段函数式编程
分享到:
相关推荐
利用Python语言编程实现机器学习和自然语言处理。具体包括:1.Building your NLP vocabulary. 2.Exploring Document, Sentence and Character Level Embeddings. 3.Transforming Text into Data Structures. 4.Word ...
Practical-time-series-analysis-master-time-series-data-processing-visualization-and-modeling-using-Python.pdf
Understand the importance of data analysis and master its processing steps Get comfortable using Python and its associated data analysis libraries such as Pandas, NumPy, and SciPy Clean and transform ...
Learn how to use Apache Spark for processing Big Data efficiently Book Description Join Frank Kane, who worked on Amazon and IMDb's machine learning algorithms, as he guides you on your first steps ...
从新闻和演讲到社交媒体上的非正式聊天,自然语言是最丰富,最未充分利用的数据来源之一。它不仅源于不断变化,而且始终在变化...Use Spark to scale processing power and neural networks to scale model complexity
These include natural language processing, data mining Twitter for sentiment analysis, cognitive computing with IBM Watson™, supervised machine learning with classification and regression, ...
Python数据处理
包含对一些机器学习常用数据集的处理,比如归一化、转为libsvm格式,将Libsvm格式转为常用格式、分为训练集...通常情况下,大多数人使用 Python 构建数据集,并且在一定程度上认为 Python 是数据科学的唯一编程语言。
Utilize various machine learning and natural language processing libraries such as TensorFlow, Keras, NLTK, and Gensim Manipulate and preprocess raw text data in formats such as .txt and .pdf ...
parade-A data processing engine and service. 一个数据处理引擎和服务
Python XML Processing. 17. Python Database Application Programming Interface (DB-API). 18. Process Management. 19. Multithreading. 20. Networking. 21. Security. 22. Data Structures. 23. Case ...
Python Text Processing with NLTK 2.0 Cookbook is your handy and illustrative guide, which will walk you through all the Natural Language Processing techniques in a step-by-step manner. It will ...
从新闻和演讲到社交媒体上的非正式聊天,自然语言是最丰富,最未充分利用的数据来源之一。它不仅源于不断变化,而且始终在变化...Use Spark to scale processing power and neural networks to scale model complexity
Data-Processing-using-Python
$ cd data-processing $ python3 -m venv venv $ source venv/bin/activate (venv) $ pip3 install --upgrade pip (venv) $ pip3 install . 剧本 脚本位于scripts/文件夹中,应从根目录运行: $ scripts/[removed] ...
This book examines how to go about obtaining, processing, storing, managing and analyzing data using the Python programming language. You will use Python and other open source tools to wrangle data ...
Written by Wes McKinney, the main author of the pandas library, Python for Data Analysis also serves as a practical, modern introduction to scientific computing in Python for data-intensive ...
使用Python和PySpark进行数据分析可以帮助您解决使用PySpark进行数据科学的日常挑战。您将了解如何在从任何源(Hadoop集群、云数据存储或本地数据文件)获取数据的同时,在多台机器上扩展处理能力。一旦您了解了这些...
Manage complex projects with a programmer’s text editor Leverage the immense power of data structures Apply algorithms to process your data structures Master indispensable text parsing and processing...
The Python ecosystem of related packages and libraries supports deep information processing. This book will guide you through the process of upgrading your Python-based toolset for intelligence ...