How to make different length list to a single dataframe in python?












0















Structure of my data is in this form.



data1:



['https://www.fullstackpython.com/',
['https://www.fullstackpython.com/table-of-contents.html',
'https://www.fullstackpython.com/blog.html'],
[['Introduction',
'Development Environments',
'Web Development ',
'Web App Deployment',
'Data',
''],
['5 Years of Full Stack Python',
'GitPython and New Git Tutorials ',
'First Steps with GitPython']],
[[0.0,
0.0,
0.25,
0.29,
0.25,
0.25],
[0.0, 1.0, 0.19]]]


How to make different length list to a single Data frame in python?
I have tried with pandas DataFrame .But it wont work since each list in data1 has different length. Same problem for the zip function also.
I am expecting this structure for the list of data, not necessary as a table ,but as a data frame. I am trying some general approach ,so that any similar information can be fed into this format.



expecting this structure for the list of datas










share|improve this question

























  • posting what you've tried may help provide more context. for example, have you tried using the python zip function?

    – Garrett
    Nov 14 '18 at 13:35











  • is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

    – mistiru
    Nov 14 '18 at 14:27













  • I have tried with zip.I have made the necessary edits in the question.

    – 9113303
    Nov 15 '18 at 4:32
















0















Structure of my data is in this form.



data1:



['https://www.fullstackpython.com/',
['https://www.fullstackpython.com/table-of-contents.html',
'https://www.fullstackpython.com/blog.html'],
[['Introduction',
'Development Environments',
'Web Development ',
'Web App Deployment',
'Data',
''],
['5 Years of Full Stack Python',
'GitPython and New Git Tutorials ',
'First Steps with GitPython']],
[[0.0,
0.0,
0.25,
0.29,
0.25,
0.25],
[0.0, 1.0, 0.19]]]


How to make different length list to a single Data frame in python?
I have tried with pandas DataFrame .But it wont work since each list in data1 has different length. Same problem for the zip function also.
I am expecting this structure for the list of data, not necessary as a table ,but as a data frame. I am trying some general approach ,so that any similar information can be fed into this format.



expecting this structure for the list of datas










share|improve this question

























  • posting what you've tried may help provide more context. for example, have you tried using the python zip function?

    – Garrett
    Nov 14 '18 at 13:35











  • is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

    – mistiru
    Nov 14 '18 at 14:27













  • I have tried with zip.I have made the necessary edits in the question.

    – 9113303
    Nov 15 '18 at 4:32














0












0








0


0






Structure of my data is in this form.



data1:



['https://www.fullstackpython.com/',
['https://www.fullstackpython.com/table-of-contents.html',
'https://www.fullstackpython.com/blog.html'],
[['Introduction',
'Development Environments',
'Web Development ',
'Web App Deployment',
'Data',
''],
['5 Years of Full Stack Python',
'GitPython and New Git Tutorials ',
'First Steps with GitPython']],
[[0.0,
0.0,
0.25,
0.29,
0.25,
0.25],
[0.0, 1.0, 0.19]]]


How to make different length list to a single Data frame in python?
I have tried with pandas DataFrame .But it wont work since each list in data1 has different length. Same problem for the zip function also.
I am expecting this structure for the list of data, not necessary as a table ,but as a data frame. I am trying some general approach ,so that any similar information can be fed into this format.



expecting this structure for the list of datas










share|improve this question
















Structure of my data is in this form.



data1:



['https://www.fullstackpython.com/',
['https://www.fullstackpython.com/table-of-contents.html',
'https://www.fullstackpython.com/blog.html'],
[['Introduction',
'Development Environments',
'Web Development ',
'Web App Deployment',
'Data',
''],
['5 Years of Full Stack Python',
'GitPython and New Git Tutorials ',
'First Steps with GitPython']],
[[0.0,
0.0,
0.25,
0.29,
0.25,
0.25],
[0.0, 1.0, 0.19]]]


How to make different length list to a single Data frame in python?
I have tried with pandas DataFrame .But it wont work since each list in data1 has different length. Same problem for the zip function also.
I am expecting this structure for the list of data, not necessary as a table ,but as a data frame. I am trying some general approach ,so that any similar information can be fed into this format.



expecting this structure for the list of datas







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 4:34







9113303

















asked Nov 14 '18 at 12:52









91133039113303

334112




334112













  • posting what you've tried may help provide more context. for example, have you tried using the python zip function?

    – Garrett
    Nov 14 '18 at 13:35











  • is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

    – mistiru
    Nov 14 '18 at 14:27













  • I have tried with zip.I have made the necessary edits in the question.

    – 9113303
    Nov 15 '18 at 4:32



















  • posting what you've tried may help provide more context. for example, have you tried using the python zip function?

    – Garrett
    Nov 14 '18 at 13:35











  • is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

    – mistiru
    Nov 14 '18 at 14:27













  • I have tried with zip.I have made the necessary edits in the question.

    – 9113303
    Nov 15 '18 at 4:32

















posting what you've tried may help provide more context. for example, have you tried using the python zip function?

– Garrett
Nov 14 '18 at 13:35





posting what you've tried may help provide more context. for example, have you tried using the python zip function?

– Garrett
Nov 14 '18 at 13:35













is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

– mistiru
Nov 14 '18 at 14:27







is data1 your input? or what you want to obtain? (and for each case, what is the other one?)

– mistiru
Nov 14 '18 at 14:27















I have tried with zip.I have made the necessary edits in the question.

– 9113303
Nov 15 '18 at 4:32





I have tried with zip.I have made the necessary edits in the question.

– 9113303
Nov 15 '18 at 4:32












1 Answer
1






active

oldest

votes


















1














If the source data format is consistent with the example, the "rows" could be looped over in the following way, and then converted to a DataFrame.



In [1]: src = ['https://www.fullstackpython.com/',
...: ['https://www.fullstackpython.com/table-of-contents.html',
...: 'https://www.fullstackpython.com/blog.html'],
...: [['Introduction', 'Development Environments', 'Web Development ',
...: 'Web App Deployment', 'Data', ''],
...: ['5 Years of Full Stack Python',
...: 'GitPython and New Git Tutorials ',
...: 'First Steps with GitPython']],
...: [[0.0, 0.0, 0.25, 0.29, 0.25, 0.25],
...: [0.0, 1.0, 0.19]]]

In [2]: site, pages, nested_titles, nested_values = src

In [3]: data =
...: for page, titles, values in zip(pages, nested_titles, nested_values):
...: for title, value in zip(titles, values):
...: data.append((site, page, title, value))
...: df = pd.DataFrame(data, columns=['Site', 'Page', 'Title', 'Value'])

In [4]: df
Out[4]:
Site Page Title Value
0 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Introduction 0.00
1 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Development Environments 0.00
2 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web Development 0.25
3 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web App Deployment 0.29
4 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Data 0.25
5 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... 0.25
6 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html 5 Years of Full Stack Python 0.00
7 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html GitPython and New Git Tutorials 1.00
8 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html First Steps with GitPython 0.19





share|improve this answer
























  • For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

    – 9113303
    Nov 16 '18 at 6:53













  • Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

    – Garrett
    Nov 16 '18 at 12:14











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300698%2fhow-to-make-different-length-list-to-a-single-dataframe-in-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If the source data format is consistent with the example, the "rows" could be looped over in the following way, and then converted to a DataFrame.



In [1]: src = ['https://www.fullstackpython.com/',
...: ['https://www.fullstackpython.com/table-of-contents.html',
...: 'https://www.fullstackpython.com/blog.html'],
...: [['Introduction', 'Development Environments', 'Web Development ',
...: 'Web App Deployment', 'Data', ''],
...: ['5 Years of Full Stack Python',
...: 'GitPython and New Git Tutorials ',
...: 'First Steps with GitPython']],
...: [[0.0, 0.0, 0.25, 0.29, 0.25, 0.25],
...: [0.0, 1.0, 0.19]]]

In [2]: site, pages, nested_titles, nested_values = src

In [3]: data =
...: for page, titles, values in zip(pages, nested_titles, nested_values):
...: for title, value in zip(titles, values):
...: data.append((site, page, title, value))
...: df = pd.DataFrame(data, columns=['Site', 'Page', 'Title', 'Value'])

In [4]: df
Out[4]:
Site Page Title Value
0 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Introduction 0.00
1 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Development Environments 0.00
2 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web Development 0.25
3 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web App Deployment 0.29
4 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Data 0.25
5 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... 0.25
6 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html 5 Years of Full Stack Python 0.00
7 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html GitPython and New Git Tutorials 1.00
8 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html First Steps with GitPython 0.19





share|improve this answer
























  • For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

    – 9113303
    Nov 16 '18 at 6:53













  • Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

    – Garrett
    Nov 16 '18 at 12:14
















1














If the source data format is consistent with the example, the "rows" could be looped over in the following way, and then converted to a DataFrame.



In [1]: src = ['https://www.fullstackpython.com/',
...: ['https://www.fullstackpython.com/table-of-contents.html',
...: 'https://www.fullstackpython.com/blog.html'],
...: [['Introduction', 'Development Environments', 'Web Development ',
...: 'Web App Deployment', 'Data', ''],
...: ['5 Years of Full Stack Python',
...: 'GitPython and New Git Tutorials ',
...: 'First Steps with GitPython']],
...: [[0.0, 0.0, 0.25, 0.29, 0.25, 0.25],
...: [0.0, 1.0, 0.19]]]

In [2]: site, pages, nested_titles, nested_values = src

In [3]: data =
...: for page, titles, values in zip(pages, nested_titles, nested_values):
...: for title, value in zip(titles, values):
...: data.append((site, page, title, value))
...: df = pd.DataFrame(data, columns=['Site', 'Page', 'Title', 'Value'])

In [4]: df
Out[4]:
Site Page Title Value
0 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Introduction 0.00
1 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Development Environments 0.00
2 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web Development 0.25
3 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web App Deployment 0.29
4 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Data 0.25
5 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... 0.25
6 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html 5 Years of Full Stack Python 0.00
7 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html GitPython and New Git Tutorials 1.00
8 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html First Steps with GitPython 0.19





share|improve this answer
























  • For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

    – 9113303
    Nov 16 '18 at 6:53













  • Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

    – Garrett
    Nov 16 '18 at 12:14














1












1








1







If the source data format is consistent with the example, the "rows" could be looped over in the following way, and then converted to a DataFrame.



In [1]: src = ['https://www.fullstackpython.com/',
...: ['https://www.fullstackpython.com/table-of-contents.html',
...: 'https://www.fullstackpython.com/blog.html'],
...: [['Introduction', 'Development Environments', 'Web Development ',
...: 'Web App Deployment', 'Data', ''],
...: ['5 Years of Full Stack Python',
...: 'GitPython and New Git Tutorials ',
...: 'First Steps with GitPython']],
...: [[0.0, 0.0, 0.25, 0.29, 0.25, 0.25],
...: [0.0, 1.0, 0.19]]]

In [2]: site, pages, nested_titles, nested_values = src

In [3]: data =
...: for page, titles, values in zip(pages, nested_titles, nested_values):
...: for title, value in zip(titles, values):
...: data.append((site, page, title, value))
...: df = pd.DataFrame(data, columns=['Site', 'Page', 'Title', 'Value'])

In [4]: df
Out[4]:
Site Page Title Value
0 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Introduction 0.00
1 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Development Environments 0.00
2 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web Development 0.25
3 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web App Deployment 0.29
4 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Data 0.25
5 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... 0.25
6 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html 5 Years of Full Stack Python 0.00
7 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html GitPython and New Git Tutorials 1.00
8 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html First Steps with GitPython 0.19





share|improve this answer













If the source data format is consistent with the example, the "rows" could be looped over in the following way, and then converted to a DataFrame.



In [1]: src = ['https://www.fullstackpython.com/',
...: ['https://www.fullstackpython.com/table-of-contents.html',
...: 'https://www.fullstackpython.com/blog.html'],
...: [['Introduction', 'Development Environments', 'Web Development ',
...: 'Web App Deployment', 'Data', ''],
...: ['5 Years of Full Stack Python',
...: 'GitPython and New Git Tutorials ',
...: 'First Steps with GitPython']],
...: [[0.0, 0.0, 0.25, 0.29, 0.25, 0.25],
...: [0.0, 1.0, 0.19]]]

In [2]: site, pages, nested_titles, nested_values = src

In [3]: data =
...: for page, titles, values in zip(pages, nested_titles, nested_values):
...: for title, value in zip(titles, values):
...: data.append((site, page, title, value))
...: df = pd.DataFrame(data, columns=['Site', 'Page', 'Title', 'Value'])

In [4]: df
Out[4]:
Site Page Title Value
0 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Introduction 0.00
1 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Development Environments 0.00
2 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web Development 0.25
3 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Web App Deployment 0.29
4 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... Data 0.25
5 https://www.fullstackpython.com/ https://www.fullstackpython.com/table-of-conte... 0.25
6 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html 5 Years of Full Stack Python 0.00
7 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html GitPython and New Git Tutorials 1.00
8 https://www.fullstackpython.com/ https://www.fullstackpython.com/blog.html First Steps with GitPython 0.19






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 5:51









GarrettGarrett

21.8k34544




21.8k34544













  • For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

    – 9113303
    Nov 16 '18 at 6:53













  • Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

    – Garrett
    Nov 16 '18 at 12:14



















  • For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

    – 9113303
    Nov 16 '18 at 6:53













  • Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

    – Garrett
    Nov 16 '18 at 12:14

















For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

– 9113303
Nov 16 '18 at 6:53







For displaying the data frame completely on the screen i have used 'pd.set_option('display.max_columns', None) ' comment. But still 'Site ' ,'Page ' is there. df[7:8] appears in 3 lines. Why its not displayed at a single structure?

– 9113303
Nov 16 '18 at 6:53















Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

– Garrett
Nov 16 '18 at 12:14





Not exactly sure what you're seeing (feel free to open a new question if needed), but also check the max_rows and max_colwidth display settings, or try df.to_string() to bypass the display settings

– Garrett
Nov 16 '18 at 12:14




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300698%2fhow-to-make-different-length-list-to-a-single-dataframe-in-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python