不确定是否可以在 pandas Styler 对象的框架下利用 matplotlib 的DivergingNorm 来绘制颜色图。举个例子:
import pandas as pd
import matplotlib.cm
# retrieve red-yellow-green diverging color map
cmap = matplotlib.cm.get_cmap('RdYlGn')
# create sample pd.DataFrame
ix = pd.date_range(start=pd.Timestamp(2020, 1, 1), periods=4)
df = pd.DataFrame(index=ix, columns=['D/D CHANGE'], data=[-1, 0, 2, 5])
df.style.background_gradient(cmap=cmap)
Run Code Online (Sandbox Code Playgroud)
理想情况下,只有负(正)值才会显示为红色(绿色)。
给定两个索引相同的 pd.Series 字符串,检查第一个 pd.Series 的每个元素是否是第二个 pd.Series 的相应元素的子字符串的最有效方法是什么?
例子:
s1 = pd.Series(['cat', 'dog', 'ham'])
s2 = pd.Series(['catbird', 'frog', 'hamster'])
pd.Series([t[0] in t[1] for t in zip(s1, s2)], index=s1.index)
Run Code Online (Sandbox Code Playgroud)
产量
0 True
1 False
2 True
dtype: bool
Run Code Online (Sandbox Code Playgroud) 是否有 Pythonic 方式(无循环或递归)来检查两个以上的pd.DataFrames(例如,pd.DataFrames 的列表)是否彼此相等?