我有一个小的 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,
我正在尝试学习在 ipython 笔记本中操作和显示这些数据,就像在常规电子表格程序中一样。所以当我在笔记本中运行以下行时:
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
我得到了一个非常漂亮的 HTML 数据表......在原始 CSV 文件中有一个空白单元格的地方到处都是“NaN”。
我理解“为什么” NaN 对于以后的计算是必要的,但它确实让观众难以阅读表格(我的观点)。
是否有一种好的/简单/简单的方法来抑制在 ipython 笔记本中显示的 HTML 表中显示“NaN”?