0

How to convert list object to Pandas Dataframe with defined format?

Printed list has this output (Jupyter):

(u'variable',    price  threshold
0   13.5      100.0
1   10.0        NaN)
(u'standard',    price  threshold
0   12.5      300.0
1   11.0        NaN)
(u'fixed',    price  threshold
0   14.5      250.0
1   10.1      200.0
2    9.0        NaN)
(u'standing-charge',    price
0      9)

Converted to Pandas Dataframe:

    0               1
0   variable        price threshold 0 13.5 100.0 1 10...
1   standard        price threshold 0 12.5 300.0 1 11...
2   fixed           price threshold 0 14.5 250.0 1 10...
3   standing-charge price 0 9

I need:

type       price  threshold
variable    13.5   100
variable    10.0   NaN
...

Please, help ;)

9
  • What are the elements in those lists? DataFrames? Commented May 26, 2016 at 19:53
  • Oh, and the index of you DataFrame has to be unique, so your I need is not possible. Commented May 26, 2016 at 19:55
  • It's output from parsing json file: rows_list = [] for index, row in ds.iterrows(): a = {} a = row['plan'], json_normalize(row['rates']) rows_list.append(a) print rows_list Commented May 26, 2016 at 19:57
  • type(rows_list) is list Commented May 26, 2016 at 19:58
  • How to parse this format? Haven't seen any similar format yet. Commented May 26, 2016 at 20:02

1 Answer 1

1

After you clearified what is in you list, you could do something like this:

df = pd.DataFrame()
for key, df2 in row_list:
    df2['index'] = key
    df = df.append(df2, ignore_index=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.