简体   繁体   English

Python 中的...是什么意思?

[英]What does ... mean in Python?

I am an elementary Python programmer and have been using this module called "Pybaseball" to analyze sabermetrics data.我是一名初级 Python 程序员,一直在使用这个名为“Pybaseball”的模块来分析 sabermetrics 数据。 When using this module, I came across a problem when trying to retrieve information from the program.使用此模块时,我在尝试从程序中检索信息时遇到了问题。 The program reads a CSV file from any baseball stats site and outputs it onto a program for ease of use but the problem is that some of the information is not shown and is instead all replaced with a "...".该程序从任何棒球统计数据站点读取 CSV 文件并将其输出到程序中以方便使用,但问题是某些信息未显示,而是全部替换为“...”。 An example of this is shown:显示了一个示例:

from pybaseball import batting_stats_range

data = batting_stats_range('2017-05-01', '2017-05-08')

print(data.head())

I should be getting:我应该得到:

https://github.com/jldbc/pybaseball#batting-stats-hitting-stats-for-players-within-seasons-or-during-a-specified-time-period https://github.com/jldbc/pybaseball#batting-stats-hitting-stats-for-players-within-seasons-or-during-a-specified-time-period

But the information is cutoff from 'TM' all the way to 'CS' and is replaced with a... on my code.但是信息从“TM”一直到“CS”都被切断了,并且在我的代码上被替换为...。 Can someone explain to me why this happens and how I can prevent it?有人可以向我解释为什么会发生这种情况以及如何预防吗?

As the docs states, head() is meant for "quickly testing if your object has the right type of data in it."正如文档所述, head()旨在“快速测试您的 object 中是否包含正确类型的数据”。 So, it is expected that some data may not show because it is collapsed.因此,预计某些数据可能不会显示,因为它已折叠。

If you need to analyze the data with more detail you can access specific columns with other methods.如果您需要更详细地分析数据,您可以使用其他方法访问特定列。 For example, using iloc() .例如,使用iloc() You can read more about it here , but essentially you can "ask" for a slice of those columns and then apply a new slice to get only nrows .您可以在此处阅读有关它的更多信息,但基本上您可以“请求”这些列的一部分,然后应用新的部分来仅获取nrows

Another example would be loc() , docs here .另一个例子是loc()这里的文档。 The main difference being that loc() uses labels (column names) to filter data instead of numerical order of columns.主要区别在于loc()使用标签(列名)来过滤数据而不是列的数字顺序。 You can filter a subset of specific columns and then get a sample of rows from that.您可以过滤特定列的子集,然后从中获取行样本。

So, to answer your question "..." is pandas's way of collapsing data in order to get a prettier view of the results.因此,回答您的问题“...”是 pandas 折叠数据以获得更漂亮的结果视图的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM