这与 this question 是同一个问题, 它被标记为 this one 的副本.
问题以及我仍在询问的原因是所提供的解决方案(使用 pandas.read_clipboard()
)目前不起作用。
我使用 Python 3.5,每当我尝试从剪贴板复制数据时,我都会收到错误消息:
“看来内核意外死亡”seems to be restricted to 3.5 .
有没有其他方法可以在 pandas 数据框中获取如下所示的简单数据框,而无需手动输入或降级 Python?
c1 c2 c3 c4
0 1 2 2 1
1 1 3 2 3
2 3 4 4 3
3 4 5 6 5
4 5 6 9 7
在 R
中,我将使用 read.table()
和 text=
参数
感谢您的帮助。
最佳答案
您可以将 io.StringIO
与 pd.read_table
一起使用:
import io
s = '''
c1 c2 c3 c4
0 1 2 2 1
1 1 3 2 3
2 3 4 4 3
3 4 5 6 5
4 5 6 9 7
'''
pd.read_table(io.StringIO(s), delim_whitespace=True)
Out:
c1 c2 c3 c4
0 1 2 2 1
1 1 3 2 3
2 3 4 4 3
3 4 5 6 5
4 5 6 9 7
关于python - 将数据粘贴到 Pandas 数据框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40914399/