pandas 如何*不*在ipython笔记本(熊猫数据框的html表)中显示'NaN'?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19215383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to *not* display 'NaN' in ipython notebook (html table of pandas dataframe)?
提问by memilanuk
I have a small CSV file of real-world data from tests performed on different days, etc. Not all of the same parameters were tested in each session, so there are a bunch of blank cells sprinkled around the original spreadsheet.
我有一个小的 CSV 文件,其中包含在不同日期等进行的测试的真实世界数据。并非在每个会话中都测试了所有相同的参数,因此原始电子表格周围散布着一堆空白单元格。
Tuner Location,200,210,220,230,240,250,260,270,280
07/17 #1,,,0.319,0.319,0.233,,0.215,,0.3355
07/21 #1,,0.539,0.482,0.034,0.343,0.478,0.285,0.01,0.538
07/21 #2,,,0.107,0.407,0.559,,0.185,0.439,0.36
07/21 #3,,,0.127,,,,,,
07/22 #1,0.316,0.201,0.646,,,,,,
07/22 #2,,0.098,0.138,0.134,0.194,,,,
07/22 #3,,0.216,0.187,,,,,,
07/27 #1,,0.118,0.065,0.013,1.013,,,,
08/05 #1,,,,,,,0.032,,
08/05 #2,,,,,,,0.128,,
08/05 #3,,,,,,0.235,0.159,0.324,
08/05 #4,,,,,,,0.398,,
08/05 #5,,,,,,0.214,0.121,0.121,
I'm trying to learn to manipulate and display this data in ipython notebook like I would in a regular spreadsheet program. so when I run the following lines inside a notebook:
我正在尝试学习在 ipython notebook 中操作和显示这些数据,就像在常规电子表格程序中一样。所以当我在笔记本中运行以下几行时:
import pandas as pd
# Set print option so the dataframe will be represented as HTML instead of plain text
pd.core.format.set_printoptions(notebook_repr_html=True)
# Read in csv file as a pandas dataframe
df = pd.read_csv('tuner-data.csv')
# View the HTML representation
df
I get a very nice looking HTML table of the data... with 'NaN' everywhere there was a blank cell in the original CSV file.
我得到了一个非常漂亮的 HTML 数据表......在原始 CSV 文件中到处都有一个空白单元格的“NaN”。
I understand 'why' NaN is necessary for later calculations, but it really makes the table hard for viewers to read (my opinion).
我理解“为什么” NaN 对以后的计算是必要的,但它确实让观众难以阅读表格(我的意见)。
Is there a good/easy/simple way to suppress the display of 'NaN' in the HTML table displayed in ipython notebook?
有没有一种好的/简单/简单的方法来抑制 ipython notebook 中显示的 HTML 表中“NaN”的显示?

