import pandas as pd import numpy as np n = ["Annie", "Charles", "David", "Sam"] g = [80, 90, 75, 78] # create a data frame using one of lists df = pd.DataFrame(n, columns=["name"]) print(df, "\n") # add another list to the data frame df.insert(len(df.columns), "grade", g) print(df, "\n") # dertermine whether pass or not and create a new column for it df["pass"] = np.where(df["grade"] >=80, "yes", "no") print(df, "\n")
No comments:
Post a Comment