1

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

  x y
1 1 a
2 2 b
3 3 c

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)

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

EdChum
  • 376,765
  • 198
  • 813
  • 562
Pierre L
  • 28,203
  • 6
  • 47
  • 69
  • What will you be using this for afterwards and what is the OS? I ask because you can do `pd.read_clipboard()` in `pandas` and there is this question: http://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-windows-clipboard-from-python – EdChum Nov 05 '15 at 14:20
  • After, reshaping and manipulation of the data would be done. Your suggestion worked really well. Thank you. if you would like to add an answer, please do. The answer linked does not have a `pandas` solution. – Pierre L Nov 05 '15 at 14:24

1 Answers1

0

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

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

  2. In Python:

    import pandas as pd
    df = pd.read_clipboard()
    >>> df
    
       x  y
    1  1  a
    2  2  b
    3  3  c
    
Pierre L
  • 28,203
  • 6
  • 47
  • 69