1

I have a list_of_data_lists that consists of:

[datetime.datetime(2019, 12, 22, 0, 49, 7), 26.3]
[datetime.datetime(2019, 12, 22, 2, 6, 24), 25.5]
[datetime.datetime(2019, 12, 22, 2, 36, 57), 26.7]
[datetime.datetime(2019, 12, 22, 3, 2, 49), 25.7]
[datetime.datetime(2019, 12, 22, 5, 26, 30), 27.9]
[datetime.datetime(2019, 12, 22, 5, 32, 4), 27.8]
[datetime.datetime(2019, 12, 22, 5, 50, 23), 23.5]
[datetime.datetime(2019, 12, 22, 6, 31, 3), 27.7]
[datetime.datetime(2019, 12, 22, 8, 9, 4), 26.1]
[datetime.datetime(2019, 12, 22, 9, 30, 40), 27.1]
[datetime.datetime(2019, 12, 22, 12, 27, 49), 26.5]
[datetime.datetime(2019, 12, 22, 16, 6, 10), 24.1]
[datetime.datetime(2019, 12, 22, 17, 21, 35), 26.3]
[datetime.datetime(2019, 12, 22, 17, 28, 54), 28.0]
[datetime.datetime(2019, 12, 22, 18, 4, 52), 26.7]
[datetime.datetime(2019, 12, 22, 22, 23, 24), 23.5]
[datetime.datetime(2019, 12, 22, 22, 51, 10), 26.0]
[datetime.datetime(2019, 12, 22, 23, 30, 14), 23.6]

And want to put this into pandas dataframe, under columns date_and_time and data_value for data_list[0] and data_list[1] in the list_of_data_lists correspond to. How can this be done?

1 Answer 1

1

IIUC, just pass list_of_data_lists to dataframe constructor

import datetime
list_of_data_lists = [
        [datetime.datetime(2019, 12, 22, 0, 49, 7), 26.3],
        [datetime.datetime(2019, 12, 22, 2, 6, 24), 25.5],
        [datetime.datetime(2019, 12, 22, 2, 36, 57), 26.7],
        [datetime.datetime(2019, 12, 22, 3, 2, 49), 25.7],
        [datetime.datetime(2019, 12, 22, 5, 26, 30), 27.9],
        [datetime.datetime(2019, 12, 22, 5, 32, 4), 27.8],
        [datetime.datetime(2019, 12, 22, 5, 50, 23), 23.5],
        [datetime.datetime(2019, 12, 22, 6, 31, 3), 27.7],
        [datetime.datetime(2019, 12, 22, 8, 9, 4), 26.1],
        [datetime.datetime(2019, 12, 22, 9, 30, 40), 27.1],
        [datetime.datetime(2019, 12, 22, 12, 27, 49), 26.5],
        [datetime.datetime(2019, 12, 22, 16, 6, 10), 24.1],
        [datetime.datetime(2019, 12, 22, 17, 21, 35), 26.3],
        [datetime.datetime(2019, 12, 22, 17, 28, 54), 28.0],
        [datetime.datetime(2019, 12, 22, 18, 4, 52), 26.7],
        [datetime.datetime(2019, 12, 22, 22, 23, 24), 23.5],
        [datetime.datetime(2019, 12, 22, 22, 51, 10), 26.0],
        [datetime.datetime(2019, 12, 22, 23, 30, 14), 23.6],
        ]

df = pd.DataFrame(list_of_data_lists, columns=['date_and_time', 'data_value'])

Out[155]:
         date_and_time  data_value
0  2019-12-22 00:49:07        26.3
1  2019-12-22 02:06:24        25.5
2  2019-12-22 02:36:57        26.7
3  2019-12-22 03:02:49        25.7
4  2019-12-22 05:26:30        27.9
5  2019-12-22 05:32:04        27.8
6  2019-12-22 05:50:23        23.5
7  2019-12-22 06:31:03        27.7
8  2019-12-22 08:09:04        26.1
9  2019-12-22 09:30:40        27.1
10 2019-12-22 12:27:49        26.5
11 2019-12-22 16:06:10        24.1
12 2019-12-22 17:21:35        26.3
13 2019-12-22 17:28:54        28.0
14 2019-12-22 18:04:52        26.7
15 2019-12-22 22:23:24        23.5
16 2019-12-22 22:51:10        26.0
17 2019-12-22 23:30:14        23.6
Sign up to request clarification or add additional context in comments.

1 Comment

sigh! I think I just had a blonde moment - it seems so obvious now!~ Thank you :)

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.