0

How do I convert a CSV table like this:

|url                   |skin   |paws|
|https://demo.foo/cats |Fur    |YES |
|https://demo.foo/dogs |Fur    |YES |
|https://demo.foo/fish |Scales |NO  |

into an inline DataFrame, like this?

df = {'url': 'https://demo.foo/cats', 'https://demo.foo/dogs', 'https://demo.foo/fish'],   
      'skin': ['Fur', 'Fur','Scales'],  
      'paws' ['YES','YES','NO']}

I have tried pd.read_csv(foo).to_dict(orient='records') and to_list, but none of them output the format above.

I've been searching for three hours for an answer. I think this is such a dumb question, that I don't think anyone has ever asked it.

heart.cooks.mind
  • 1,065
  • 1
  • 9
  • 22
  • 1
    `df.to_dict(orient='list')` ? – anky Apr 02 '20 at 18:01
  • That was it. I poured over the documentation looking for something like that, but didn't find it. How to I mark your comment as correct? – heart.cooks.mind Apr 02 '20 at 18:04
  • 1
    What do you mean by an "inline data frame"??? That is a `dict`, not a `pd.DataFrame` – juanpa.arrivillaga Apr 02 '20 at 18:04
  • Use pandas fixed width reader -- https://stackoverflow.com/questions/9721429/how-do-i-read-a-fix-width-format-text-file-in-pandas – Akarsh Jain Apr 02 '20 at 18:06
  • 1
    you could find it in the [docs](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_dict.html) : `‘list’ : dict like {column -> [values]}` , nevertheless, it is actually a duplicate :) – anky Apr 02 '20 at 18:06

0 Answers0