{ "data": { "question": { "questionId": "3062", "questionFrontendId": "2877", "categoryTitle": "pandas", "boundTopicId": 2467481, "title": "Create a DataFrame from List", "titleSlug": "create-a-dataframe-from-list", "content": "

Write a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.

\n\n

The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput:\nstudent_data:\n[\n  [1, 15],\n  [2, 11],\n  [3, 11],\n  [4, 20]\n]\nOutput:\n+------------+-----+\n| student_id | age |\n+------------+-----+\n| 1          | 15  |\n| 2          | 11  |\n| 3          | 11  |\n| 4          | 20  |\n+------------+-----+\nExplanation:\nA DataFrame was created on top of student_data, with two columns named student_id and age.\n
\n", "translatedTitle": "从表中创建 DataFrame", "translatedContent": "

编写一个解决方案,基于名为  student_data 的二维列表 创建 一个 DataFrame 。这个二维列表包含一些学生的 ID 和年龄信息。

\n\n

DataFrame 应该有两列, student_id 和 age,并且与原始二维列表的顺序相同。

\n\n

返回结果格式如下示例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nstudent_data:\n[\n  [1, 15],\n  [2, 11],\n  [3, 11],\n  [4, 20]\n]\n输出:\n+------------+-----+\n| student_id | age |\n+------------+-----+\n| 1          | 15  |\n| 2          | 11  |\n| 3          | 11  |\n| 4          | 20  |\n+------------+-----+\n解释:\n基于 student_data 创建了一个 DataFrame,包含 student_id 和 age 两列。\n
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 1, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef createDataframe(student_data: List[List[int]]) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"2.5K\", \"totalSubmission\": \"3.3K\", \"totalAcceptedRaw\": 2493, \"totalSubmissionRaw\": 3266, \"acRate\": \"76.3%\"}", "hints": [ "Consider using a built-in function in pandas library and specifying the column names within it." ], "solution": null, "status": null, "sampleTestCase": "[[1,15],[2,11],[3,11],[4,20]]", "metaData": "{\n \"name\": \"create_a_dataframe\",\n \"params\": [\n {\n \"name\": \"student_data\",\n \"type\": \"list>\"\n }\n ],\n \"return\": {\n \"type\": \"DataFrame\"\n },\n \"data\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "envInfo": "{\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "[[1,15],[2,11],[3,11],[4,20]]", "__typename": "QuestionNode" } } }