Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dataframe from list

I am trying to create a dataframe from multiple lists. Each list is a row that i want to append to my dataframe.

for i in tmpList:
    data = data.append(getTFSData(i))

tmpList contains a list of IDs, getTFSData() fetches some data via webrequest und returns a list of those values:

responseDict = [
    responseRaw['id'],
    responseRaw['Title'],
    responseRaw['state'],
    responseRaw['IterationPath'],
    responseRaw['Tags']
]

return responseDict

I am expecting each value of the list to be a coloumn, but instead each value is a row in coloumn 0

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You better keep the response raw dictionary:

import random
import pandas as pd


def main():
    ids_list = [1, 2, 3, 4, 5]
    data = [get_tfs_data(data_id) for data_id in ids_list]
    df = pd.DataFrame(data)
    print(df)


def get_tfs_data(data_id):
    response_raw = {
        "id": random.randint(0, 10),
        "Title": random.randint(0, 10),
        "state": random.randint(0, 10),
        "IterationPath": random.randint(0, 10),
        "Tags": random.randint(0, 10),
    }
    return response_raw


if __name__ == "__main__":
    main()
   id  Title  state  IterationPath  Tags
0   1      3      9              9     3
1   4      3      2              0     9
2   5      2      2              2     3
3   3      1      7             10     6
4   0      8      1              6     5
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading