我想知道是否可以選擇Pandas在 R 塊中使用在 Python 塊中創建的資料框來可視化資料框。這是一些可重現的代碼:
---
title: "How to use Pandas Dataframe in R chunk"
format: html
engine: knitr
---
Example code:
```{python}
import pandas as pd
df = pd.DataFrame(data = [[1,2],[2,3],[3,3]], columns = ['v1', 'v2'])
print(df)
```
```{r}
library(ggplot2)
ggplot(data = df, aes(x = v1, y = v2)) geom_point()
```
這會產生以下錯誤:
Error in `ggplot()`:
! You're passing a function as global data.
Have you misspelled the `data` argument in `ggplot()`
Backtrace:
1. ggplot2::ggplot(data = df, aes(x = v1, y = v2))
2. ggplot2:::ggplot.function(data = df, aes(x = v1, y = v2))
這當然會發生,因為它找不到df在 python 塊中創建的資料框。我還加載了reticulate包并嘗試py$df在 R 塊中使用但沒有成功。所以我想知道是否有人知道如何Pandas在你的 R 塊中使用資料框來可視化它Quarto?
uj5u.com熱心網友回復:
從
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/515291.html
標籤:Pythonr熊猫四开
上一篇:If陳述句回傳數字而不是變數名
