美文网首页
Python和R通用的数据格式-feather

Python和R通用的数据格式-feather

作者: MJades | 来源:发表于2021-10-11 15:43 被阅读0次

    Part 1. 安装

    • R

      devtools::install_github("wesm/feather/R")
      
    • Python

      pip install feather-format
      

    Part 2. 使用

    • Python中读取、保存

      import feather
      # 读取
      df = pd.read_feather('R_data.feather')
      df
      
       # 保存
      df.to_feather('data.feather')
      
    报错

    报错原因:将DataFrame存储为.feather文件时,需要DataFrame的index为默认的顺序,因此需要将index更改为默认的顺序。

      import feather
      df = df.reset_index()
      df.to_feather('data.feather')
    

    即可保存成功


    python中格式
    • R语言读取、保存

      library(feather) 
      df <- read_feather('df_diff_from new and old.feather')
      View(df)
      
    R读取结果展示
    path <- "R_data.feather" 
    write_feather(df, path) 
    

    参考
    https://blog.csdn.net/tanzuozhev/article/details/51088949
    https://zhuanlan.zhihu.com/p/247025752

    Part 3. 访问剪切板

    • Python

      import pyperclip 
      pyperclip.copy("hello, world")  # 将文字复制进剪切板
      pyperclip.paste()  # 将文字从剪切板复制出来
      
    • R

       # 将剪切板数据读入
       read.table(pipe("pbpaste"),header = F)
      
      # 将剪切板数据输出
       clip<-pipe("pbcopy","w")
       write.table(path,file=clip)
       close(clip)
      

    相关文章

      网友评论

          本文标题:Python和R通用的数据格式-feather

          本文链接:https://www.haomeiwen.com/subject/hcwloltx.html