Hi im trying to convert this this dataframe to a specific format. I have simplified the data to the following.
import pandas as pd
import numpy as np
student_id = [1, 2, 2, 4, 5, 5]
student_names = ["Bob", "Alex", "Alex", "Alice", "Sharon", "Sharon"]
student_status = ["Inactive", "Full Time", "Full Time", "Inactive", "Inactive", "Inactive"]
course_description = [np.nan, "Physics", "History", np.nan, "Physics", "History"]
course_paid = [np.nan, "Yes", "No", np.nan, "No", "Yes"]
enrollement = [np.nan, "Enrolled", "Not Enrolled", np.nan, "Not Enrolled", "Enrolled"]
df = pd.DataFrame(data = student_id, columns=["Student ID"])
df["Student Name"] = student_names
df["Student Status"] = student_status
df["Course Description"] = course_description
df["Course paid"] = course_paid
df["Enrollment"] = enrollement
print(df)
To
student_id = [1, 2, 4, 5]
student_names = ["Bob", "Alex", "Alice", "Sharon"]
student_status = ["Inactive", "Full Time", "Inactive", "Inactive"]
physics = [np.nan, "Enrolled", np.nan, "Not Enrolled"]
physics_paid = [np.nan, "Yes", np.nan, "No"]
history = [np.nan, "Not Enrolled", np.nan, "Enrolled"]
history_paid = [np.nan, "No", np.nan, "Yes"]
df2 = pd.DataFrame(data = student_id, columns=["Student ID"])
df2["Student Name"] = student_names
df2["Student Status"] = student_status
df2["Physics"] = physics
df2["Physics Paid"] = physics_paid
df2["History"] = history
df2["History Paid"] = history_paid
print(df2)
Any tips? Sorry, new to stackoverflow. I don't know how to show the output. The issue I have is working with the student ids in two rows.