您可以通过运行以下命令在活动的html设置中显示Jupyter笔记本:
$ jupyter nbconvert untitled.ipynb --to slides --post serve
Run Code Online (Sandbox Code Playgroud)
有没有办法以相同的幻灯片格式运行笔记本,以便允许您的单元格的实时演示/执行?
这个问题涉及在 Python 中使用与学术出版物中找到的表格相对应的格式化输出进行描述性统计的最佳实践:平均值在下面的括号中带有各自的标准偏差。最终目标是能够以 Latex 表格格式(或其他格式、html 等)导出它。
示例(Deucherta & Eugster (2018)):
在 Pandas 中进行描述性统计的经典解决方案是使用 a 的describe()方法DataFrame。
import numpy as np
import pandas as pd
# Generate a DataFrame to have an example
df = pd.DataFrame(
{"Age" : np.random.normal(20,15,5),
"Income": np.random.pareto(1,5)*20_000 }
)
# The describe method to get means and stds
df.describe().loc[["mean", "std"]].T
>>>
mean std
Age 15.322797 13.449727
Income 97755.733510 143683.686484
Run Code Online (Sandbox Code Playgroud)
我想要的是以下输出:
Age 15.32
(13.44)
Income 97755.73
(143683.68)
Run Code Online (Sandbox Code Playgroud)
有一个适用于多索引数据帧的解决方案会很好:
df2 = pd.DataFrame(
{"Age" …Run Code Online (Sandbox Code Playgroud) 我正在做一个value_counts()代表分类值的整数列。
我有一个 dict 将数字映射到与类别名称对应的字符串。
我想找到具有相应名称的索引的最佳方法。因为我对我的 4 行解决方案不满意。
df = pd.DataFrame({"weather": [1,2,1,3]})
df
>>>
weather
0 1
1 2
2 1
3 3
weather_correspondance_dict = {1:"sunny", 2:"rainy", 3:"cloudy"}
Run Code Online (Sandbox Code Playgroud)
现在我如何解决问题:
df_vc = df.weather.value_counts()
index = df_vc.index.map(lambda x: weather_correspondance_dict[x] )
df_vc.index = index
df_vc
>>>
sunny 2
cloudy 1
rainy 1
dtype: int64
Run Code Online (Sandbox Code Playgroud)
我对那个非常乏味的解决方案不满意,你有这种情况的最佳实践吗?
我正在尝试选择我的悬停显示为vline模式的行。
这是示例(取自this SO question):
days = ['2018/1/1', '2018/1/2', '2018/1/3', '2018/1/4', '2018/1/5']
data_a = [10, 34, 23, 14, 58]
data_b = [20, 13, 45, 98, 65]
data_c = [20, 23, 43, 76, 57]
df_plot = pd.DataFrame({'A': data_a, 'B': data_b, 'C': data_c}, index=days)
df_plot['dates'] = pd.to_datetime(df_plot.index, format='%Y/%m/%d')
source = ColumnDataSource(df_plot)
p = figure(x_axis_type="datetime")
p.line('dates', 'A', source=source, color='red')
p.line('dates', 'B', source=source, color='blue')
p.line('dates', 'C', source=source, color='green')
p.add_tools(HoverTool(tooltips=[("A", "@A"), ("B", "@B"), ("C", "@C")],mode = "vline"))
show(p)
Run Code Online (Sandbox Code Playgroud)
图像悬停出现在所有线条上,如果我只想悬停在红线上怎么办?
python ×3
pandas ×2
bokeh ×1
counting ×1
dataframe ×1
dictionary ×1
jupyter ×1
slideshow ×1
statistics ×1
statsmodels ×1