小编joa*_*asa的帖子

R - “文件错误(文件,ifelse(追加,“a”,“w”)):无法打开连接”

我有一个这种形式的数据框:

X1                                      X2 X3                       X4
R290601 WOVEN TWILL                    001  6                      231
009-1373  *with perforated L3-0,3      152 NA                     <NA>
R481400 THREAD                       A1282 12                    A0399
0091375 PURE SOCK                      001  6                      072
R282380 SOFTLIN W/FELT                 007  6                      072
R282480 MICROFIBRE                     001  6                      F72
R281200 ARTIFICIAL                   A0638  6                      072
Run Code Online (Sandbox Code Playgroud)

我想遍历行,对于每一行,检查第一列 (X1) 的名称并在我的计算机中创建一个具有相同名称的文件夹,并在该文件夹内创建与其名称相同的子文件夹各列 (X2)、(X3)、(X4)。当我运行脚本时,我只能看到创建了文件夹R290601 WOVEN TWILL,其中包含子文件夹0016231,但没有其他文件夹,并且出现此错误:

文件错误(文件,ifelse(追加,“a”,“w”)):无法打开连接

此外,我在第二行收到此警告:

在 dir.create(paste0(pth, df$X1[i])) 中:无法创建 dir 'C:\Users\Dev\Desktop\Joe\009-1373 *with perforated L3-0,3',原因 'Invalid argument '

我的代码是这样的:

getwd()
setwd("C:/Users/Dev/Desktop/Joe")

library(xlsx)
library(rJava)
library(xlsxjars)

#get …
Run Code Online (Sandbox Code Playgroud)

r dataframe

6
推荐指数
1
解决办法
1万
查看次数

无法在 r markdown 中编译 tex

我想使用 R 降价,当我运行时收到此消息bookdown::render_book("index.Rmd", "bookdown::pdf_book")

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Documentation.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output Documentation.tex --table-of-contents --toc-depth 2 --template "C:\PROGRA~1\R\R-35~1.3\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --number-sections --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --wrap preserve --variable "compact-title:yes" --variable tables=yes --standalone 
Error: Failed to compile Documentation.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  '"pdflatex"' not found
Please delete Documentation.md after you finish debugging the error.
Run Code Online (Sandbox Code Playgroud)

我猜是因为无法安装 Miktex,我不知道为什么。即使我以管理员身份运行,如果我选择仅为我安装的选项,一旦安装完成,我就会收到此错误消息

Administrator mode …

markdown latex r miktex r-markdown

5
推荐指数
1
解决办法
2万
查看次数

合并列中具有相同值的 2 个数据框

我有 2 个数据框。一种是这种形式:

df1:
     date      revenue
0  2016-11-17   385.943800
1  2016-11-18  1074.160340
2  2016-11-19  2980.857860
3  2016-11-20  1919.723960
4  2016-11-21   884.279340
5  2016-11-22   869.071070
6  2016-11-23   760.289260
7  2016-11-24  2481.689270
8  2016-11-25  2745.990070
9  2016-11-26  2273.413250
10 2016-11-27  2630.414900
Run Code Online (Sandbox Code Playgroud)

另一种是这种形式:

df2:

      CET    MaxTemp  MeanTemp MinTemp  MaxHumidity  MeanHumidity  MinHumidity
0  2016-11-17   11      9        7            100           85             63
1  2016-11-18   9       6        3             93           83             66
2  2016-11-19   8       6        4             93           87             76
3  2016-11-20   10      7        4             93           84             81 …
Run Code Online (Sandbox Code Playgroud)

python merge dataframe pandas

4
推荐指数
1
解决办法
3800
查看次数

相互绘制数据框列

我有这个 df :

      CET    MaxTemp  MeanTemp MinTemp  MaxHumidity  MeanHumidity  MinHumidity  revenue     events
0  2016-11-17   11      9        7            100           85             63   385.943800    rain
1  2016-11-18   9       6        3             93           83             66  1074.160340    storm
2  2016-11-19   8       6        4             93           87             76  2980.857860    
3  2016-11-20   10      7        4             93           84             81  1919.723960    rain-thunderstorm
4  2016-11-21   14     10        7            100           89             77   884.279340
5  2016-11-22   13     10        7             93           79             63   869.071070
6  2016-11-23   11      8        5            100           91             82   760.289260    fog-rain
7 …
Run Code Online (Sandbox Code Playgroud)

python matplotlib dataframe pandas plt

4
推荐指数
1
解决办法
3735
查看次数

在 R 中设置相对输出目录

我有一个 R 脚本,它从多个 xlsx 文件读取数据,将它们转换为数据帧,然后根据数据帧的行值在我的计算机的目录中创建文件夹。我在代码的开头设置了主目录,如下所示:

choose.dir(getwd(), "Choose a suitable folder")

以及创建文件夹的输出目录,如下所示:

pth <- "C:/Users/Dev/Desktop/test/"

我想在多台计算机上运行该脚本,这意味着名为pth的输出目录不会始终相同。有没有办法设置相对输出路径,以便每次运行脚本时指定我希望结果所在的位置?我试过

pth <- choose.dir(default = "", caption = "Choose the output path")

尽管弹出一个对话窗口并且我选择了所需的目录,但我看不到那里的任何文件夹。

到目前为止,这是我的代码:

#choose working directory
choose.dir(getwd(), "Choose a suitable folder")

library(xlsx)
library(tcltk)

#get file names
f = list.files("./")

#read files
dat <- lapply(tk_choose.files(caption="Choose your files"), function(i) {
  x <- read.xlsx(i, sheetIndex = 1, sheetName = NULL, startRow = 24,
                 endRow = NULL, as.data.frame = TRUE, header = FALSE, Filters = Filters[c("xlsx")])
  #return …
Run Code Online (Sandbox Code Playgroud)

r

3
推荐指数
1
解决办法
1万
查看次数

Pandas Dataframe到字典groupby索引

我有一个包含3列的数据框,所有这些都有字符串值.数据框具有以下形式:

Key Word    Synonym    Alternatives
   A          word1         NaN
   A          word2         NaN
   A          word3         word11
   B          word4         word12
   B          word5         NaN 
   B          word6         word13
   C          word7         word14
   C          word8         NaN
   C          word9         NaN
   D          word10        word15
Run Code Online (Sandbox Code Playgroud)

我想要的是将它转换为字典,它将根据Key Word列进行分组,并为每个key_word返回所有相应的同义词和替代同义词.所以,所有的值A都将指代存在于SynonymAlternativesfor A等中的相应值.有没有办法做到这一点?先感谢您.

python dictionary dataframe pandas

3
推荐指数
1
解决办法
236
查看次数

标签 统计

dataframe ×4

pandas ×3

python ×3

r ×3

dictionary ×1

latex ×1

markdown ×1

matplotlib ×1

merge ×1

miktex ×1

plt ×1

r-markdown ×1