EasyCompaniesHintWrite a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.The result format is in the following example. Example 1:Input:student_data:[ [1, 15], [2, 11], [3, 11], [4, 20]]Output:+------------+-----+| student_id | age |+------------+-----+| 1 | 15 || 2 | 11 || 3 | 11 || 4 | 20 |+------------+-----+Explanation:A DataFrame was created on top of student_data, with two columns named student_id and
Question
EasyCompaniesHintWrite a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.The result format is in the following example. Example 1:Input:student_data:[ [1, 15], [2, 11], [3, 11], [4, 20]]Output:+------------+-----+| student_id | age |+------------+-----+| 1 | 15 || 2 | 11 || 3 | 11 || 4 | 20 |+------------+-----+Explanation:A DataFrame was created on top of student_data, with two columns named student_id and
Solution
To create a DataFrame from the 2D list called student_data, we can use the pandas library. Here are the steps to do so:
- Import the pandas library:
import pandas as pd
- Define the student_data 2D list:
student_data = [[1, 15], [2, 11], [3, 11], [4, 20]]
- Create the DataFrame using the student_data list:
df = pd.DataFrame(student_data, columns=['student_id', 'age'])
- Print the resulting DataFrame:
print(df)
The output will be:
student_id age
0 1 15
1 2 11
2 3 11
3 4 20
This DataFrame has two columns, 'student_id' and 'age', and is in the same order as the original 2D list.
Similar Questions
Consider the following DataFrame Gr and answer any four questions from (i)- (v) Name Age0 Rashmi A11 Harsh A22 Ganesh B13 Priya A14 Vivek B25 Anita A26 Karthik A1 5. Write down the command that will give the following output. Name Age0 Rashmi A11 Harsh A22 Ganesh B13 Priya A14 Vivek B2*1 pointa. print(Gr.iloc[0:5])b. print(Gr[0:5])c. Bothd. None6. The teacher needs to add a column called Percentage with the following data [92,89,None,95,68,None,93] Help her to identify the correct set of statement/s from the given options :*1 pointa. Gr.column[‘Percentage’]=[92,89,None, 95,68,None ,93]b. Gr[‘ Percentage’]=[92,89,None, 95,68,None ,93]c. Gr.loc[‘Percentage’]= [92,89,None,95,68,None,93]d. Both (b) and (c) are correct7. Which of the following statement/s will drop the column Grade by name?*1 pointa. Gr.drop[‘Grade’]b. Gr.drop(‘Grade’, axis=1)c. Both a & bd. None of the above8. Which of the following command will display the column labels of the DataFrame?*1 pointa. print(Gr.columns())b. print(Gr.column())c. print(Gr.column)d. print(Gr.Columns)
tudent_data = data.frame(student_id=c(1:4), student_name=c(‘Ram’,‘Harish’,‘Pradeep’,‘Rajesh’))1 pointChoose the correct command to add a column named student_dept to the dataframe student_data. student_datastudent_dept=c(“Commerce”, “Biology”, “English”, “Tamil”) student_data[“student_dept”]= c(“Commerce”,“Biology”, “English”,“Tamil”) student_dept= student_data[c(“Commerce”,“Biology”,“English”,“Tamil”)] None of the above
age=np.array([15,17,19,20,14,21,16,19,13,20,22,23,21,16,18,19,20,15,17,18])height=np.array([156,144,180,162,152,157,154,155,151,150,158,179,126,182,183,154,159,160,172,149])Given age and height of 20 students in two different numpy arrays with name age and height (in cms). Print the age of those students whose height is above 155 cm.Print the Numpy array.
Write command to create a dataframe to store marks of 3 subjects . columns can be named as ["GE", "SEC","VAC "]. Rows are indexed by rollno of the students [25,30,50]
Based on the dataframe generated in practice 1, use Loop to create a new columnnamed Age_Comparison indicating whether the age of a person is higher, lower or the same asthe average age in the dataset. (You can use Higher/Same/Lower).
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.