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
"Python-Data-Processing-master" 是一个专注于Python数据处理的项目,它可能包含了各种用于数据清洗、转换、分析和可视化的工具和方法。这个项目的重点是利用Python的强大功能来高效地处理各种数据集。 在Python中...
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, ...
MaxCompute,原名为ODPS(Open Data Processing Service),是阿里云推出的一种大规模数据处理服务,支持结构化和半结构化的数据存储及在线分析处理。它具备高并发、高吞吐、低延迟的特点,广泛应用于数据仓库、数据...
print(f"Processing {data}") producer.put(my_task, "some data") # 创建消费者 worker = Worker(producer.queue) worker.start() ``` 以上代码创建了一个生产者,发布了一个任务,然后创建了一个消费者来处理...
3. **并行计算**:"pbd"可能代表“并行数据处理”(Parallel Data Processing),因此库可能涉及多线程或多进程编程,利用Python的`multiprocessing`或`concurrent.futures`等库实现。 **分布式计算** 1. **...
包含对一些机器学习常用数据集的处理,比如归一化、转为libsvm格式,将Libsvm格式转为常用格式、分为训练集...通常情况下,大多数人使用 Python 构建数据集,并且在一定程度上认为 Python 是数据科学的唯一编程语言。
- `data_processing.py`:处理数据和创建图表的函数。 - `main.py`:主程序,调用以上模块并执行发送邮件的操作。 在CTEmail-master压缩包中,你会找到这些文件,以及可能的示例数据和配置文件。为了使用CTEmail,...
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 ...
6. **并行数据处理库(Parallel Data Processing Libraries)**:例如`NumPy`和`Pandas`库,它们提供了矢量化操作和并行计算的功能,尤其适用于科学计算和数据分析。 7. **并行计算框架(Parallel Computing ...
资源分类:Python库 所属语言:Python 资源全名:data-process-0.1.14.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
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 ...
标题提到的“X-Ray Data Processing in Python-开源”意味着存在一个开源的Python库,专门用于处理X射线实验产生的数据。 描述中提到,这个开源项目提供了一个工具包,能够对X射线实验的数据进行临时整理,这意味着...
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 ...
针对标题"Single-data-file-processing.rar_single_site:www.pudn.com"及描述"单个数据文件处理,选择文本文档后可以将其转换为字符串并计算各种参数以及绘图",我们可以从中提炼出以下几个关键知识点: 1. **数据...