【问题标题】:Pasting data into a pandas dataframe将数据粘贴到熊猫数据框中
【发布时间】:2016-12-01 15:24:59
【问题描述】:

这与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= 参数

感谢您的帮助。

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    您可以将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
    

    【讨论】:

    猜你喜欢
    • 2019-01-14
    • 2020-06-03
    • 1970-01-01
    • 2018-12-07
    • 2020-12-14
    • 2015-11-12
    • 2014-02-01
    相关资源
    最近更新 更多