Skip to content Skip to sidebar Skip to footer

Convert Text Table To Pandas Dataframe

Many times when I'm trying to answer questions on Stackoverflow, the question contains a table, which I have to convert to a pandas dataframe in order to process. for example, in t

Solution 1:

Make sure the desired data set is in clipboard and use pd.read_clipboard() method.

Step by step:

  1. mark desired data set
  2. press Ctrl+C (for MS Windows)
  3. execute: df = pd.read_clipboard()

In [40]: df = pd.read_clipboard()

In [41]: df
Out[41]:
   graph     0     1     2     3     4
0      1  blue  blue  blue  blue  blue
1      2  blue  blue  blue  blue  blue
2      3  blue   red  blue  blue   red
3      4   red  blue   red   red  blue
4      5   red   red  blue   red   red
5      6  blue  blue  blue  blue  blue

Post a Comment for "Convert Text Table To Pandas Dataframe"