R的read.table'text'参数的Python翻译 [英] Python translation of R's read.table 'text' argument

查看:86
本文介绍了R的read.table'text'参数的Python翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中,如果SO上的某人将数据框发布为文本:

In R if someone on SO posts a data frame as text:

  x y
1 1 a
2 2 b
3 3 c

将突出显示并复制数据框,然后将其粘贴到R中以重新创建它:

One would highlight and copy the data frame as is, and paste it into R to recreate it:

df <- read.table(text="  x y
1 1 a
2 2 b
3 3 c", header=TRUE)

Python中复制表式数据并粘贴以使用的等效功能是什么?

What is the equivalent in Python to copy table-like data and paste to work with?

推荐答案

正如@EdChurn在评论中建议的那样,使用pandas可以非常简单地完成任务:

As @EdChurn suggested in the comments, the task is very simple and straightforward with pandas:

  1. 使用Ctrl + C(或其他方法)从原始源复制数据

  1. Copy the data from the original source with Ctrl+C (or other method)

在Python中:

import pandas as pd
df = pd.read_clipboard()
>>> df

   x  y
1  1  a
2  2  b
3  3  c

这篇关于R的read.table'text'参数的Python翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆