mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Add support to display Pandas DataFrame index using z.show() and modifies test.
This commit is contained in:
parent
702666480b
commit
6767b4041d
2 changed files with 12 additions and 7 deletions
|
|
@ -142,17 +142,19 @@ class PyZeppelinContext(object):
|
|||
"""
|
||||
limit = len(df) > self.max_result
|
||||
header_buf = StringIO("")
|
||||
header_buf.write(str(df.columns[0]))
|
||||
for col in df.columns[1:]:
|
||||
idx_name = df.index.name if df.index.name is not None else ""
|
||||
header_buf.write(idx_name)
|
||||
for col in df.columns:
|
||||
header_buf.write("\t")
|
||||
header_buf.write(str(col))
|
||||
header_buf.write("\n")
|
||||
|
||||
body_buf = StringIO("")
|
||||
rows = df.head(self.max_result).values if limit else df.values
|
||||
for row in rows:
|
||||
body_buf.write(str(row[0]))
|
||||
for cell in row[1:]:
|
||||
index = df.index.values
|
||||
for idx, row in zip(index, rows):
|
||||
body_buf.write("%html <strong>{}</strong>".format(str(idx)))
|
||||
for cell in row:
|
||||
body_buf.write("\t")
|
||||
body_buf.write(str(cell))
|
||||
body_buf.write("\n")
|
||||
|
|
|
|||
|
|
@ -159,9 +159,10 @@ public class PythonInterpreterPandasSqlTest {
|
|||
ret = python.interpret("import pandas as pd", context);
|
||||
ret = python.interpret("import numpy as np", context);
|
||||
|
||||
// given a Pandas DataFrame with non-text data
|
||||
// given a Pandas DataFrame with an index and non-text data
|
||||
ret = python.interpret("index = pd.Index([10, 11, 12, 13], name='index_name')", context);
|
||||
ret = python.interpret("d1 = {1 : [np.nan, 1, 2, 3], 'two' : [3., 4., 5., 6.7]}", context);
|
||||
ret = python.interpret("df1 = pd.DataFrame(d1)", context);
|
||||
ret = python.interpret("df1 = pd.DataFrame(d1, index=index)", context);
|
||||
assertEquals(ret.message(), InterpreterResult.Code.SUCCESS, ret.code());
|
||||
|
||||
// when
|
||||
|
|
@ -170,6 +171,8 @@ public class PythonInterpreterPandasSqlTest {
|
|||
// then
|
||||
assertEquals(ret.message(), InterpreterResult.Code.SUCCESS, ret.code());
|
||||
assertEquals(ret.message(), Type.TABLE, ret.type());
|
||||
assertTrue(ret.message().indexOf("index_name") == 0);
|
||||
assertTrue(ret.message().indexOf("13") > 0);
|
||||
assertTrue(ret.message().indexOf("nan") > 0);
|
||||
assertTrue(ret.message().indexOf("6.7") > 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue