如何解决如何在rstudio中的r对象上应用python函数.style.background_gradient()?
我第一次在 python
中尝试 rstudio
并尝试将 r 对象 用于 python-chunk
。
尝试这个的整个想法是使用python的简单渐变颜色在r中创建的df .style.background_gradient()
.
工作代码:
```{r}
library(reticulate)
```
```{python}
import pandas as pd
```
```{r}
test_iris_r_df <- iris
```
```{python}
print(r.test_iris_r_df)
```
Python 3.8.8 (C:/ProgramData/Anaconda3/python.exe)
Reticulate 1.20 REPL -- A Python interpreter in R.
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
.. ... ... ... ... ...
145 6.7 3.0 5.2 2.3 virginica
146 6.3 2.5 5.0 1.9 virginica
147 6.5 3.0 5.2 2.0 virginica
148 6.2 3.4 5.4 2.3 virginica
149 5.9 3.0 5.1 1.8 virginica
[150 rows x 5 columns]
没有得到预期的代码:
```{python}
r.test_iris_r_df.style.background_gradient(subset = 'Sepal.Length')
```
<pandas.io.formats.style.Styler object at 0x000000002BF1E910>
但我期待如下(例如):
https://www.geeksforgeeks.org/make-a-gradient-color-mapping-on-a-specified-column-in-pandas/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。