python - 将数据粘贴到 Pandas 数据框中

标签 python pandas

这与 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.StringIOpd.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/

相关文章:

python - Dataframe:从单个 ID 中提取多个 parent 并计算出现次数

python - 查找在指定时间内条目出现频率最高的系列范围(在 Pandas 中)

python - 对 pandas DataFrame 进行分组和聚合以获得摘要 DataFrame

python - 使用 Pandas 将数据分组为单独的批处理

python - 在 Tornado 中处理长请求永远不会完成

python - 清理Python中的城市名称

Python如何将数据从dataframe插入到MySQL

python - Django 在管理页面中显示一对多关系

python - 如何修复 vscode 中的 'jupyter notebook server failed to launch in time'?

python - 我有一个按钮列表,但无法访问它们