Python|熊猫 Series.to_latex()
Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持基于整数和基于标签的索引,并提供了许多用于执行涉及索引的操作的方法。
Pandas Series.to_latex()函数将对象渲染到 LaTeX 表格环境表。
Syntax: Series.to_latex(buf=None, columns=None, col_space=None, header=True, index=True, na_rep=’NaN’, formatters=None, float_format=None, sparsify=None, index_names=True, bold_rows=False, column_format=None, longtable=None, escape=None, encoding=None, decimal=’.’, multicolumn=None, multicolumn_format=None, multirow=None)
Parameter :
buf : Buffer to write to. If None, the output is returned as a string.
columns : The subset of columns to write. Writes all columns by default.
col_space : The minimum width of each column.
header : Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names.
index : Write row names (index)
na_rep : Missing data representation.
formatters : Formatter functions to apply to columns’ elements by position or name.
float_format : Format string for floating point numbers.
sparsify : Set to False for a DataFrame with a hierarchical index to print every multi-index key at each row.
Returns : If buf is None, returns the resulting LateX format as a string, otherwise, returns None.
示例 #1:使用 Series.to_latex()函数将给定的系列对象渲染到 LaTeX 表格环境表。
Python3
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio', 'Moscow'])
# Create the Datetime Index
didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='W',
periods = 6, tz = 'Europe/Berlin')
# set the index
sr.index = didx
# Print the series
print(sr)
Python3
# render to LaTeX tabular environment table.
sr.to_latex()
Python3
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, 22.78, 20.124, 18.1002])
# Print the series
print(sr)
Python3
# render to LaTeX tabular environment table.
sr.to_latex()
输出 :
现在我们将使用 Series.to_latex()函数将给定的系列对象渲染到 LaTeX 表格环境表。
Python3
# render to LaTeX tabular environment table.
sr.to_latex()
输出 :
正如我们在输出中看到的,Series.to_latex()函数已经成功地将给定的系列对象渲染到 LaTeX 表格环境表中。示例 #2:使用 Series.to_latex()函数将给定的系列对象渲染到 LaTeX 表格环境表。
Python3
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, 22.78, 20.124, 18.1002])
# Print the series
print(sr)
输出 :
现在我们将使用 Series.to_latex()函数将给定的系列对象渲染到 LaTeX 表格环境表。
Python3
# render to LaTeX tabular environment table.
sr.to_latex()
输出 :
正如我们在输出中看到的,Series.to_latex()函数已经成功地将给定的系列对象渲染到 LaTeX 表格环境表中。