Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Ravi's program builds the table with the column names symbol, z, group, period, block, radius, ie and en. These two lines stop with errors. Name each error and fix each line.
print(df["Radius"].max())
print(df[(df["block"] == "s") and (df["ie"] > 500)])
A pandas DataFrame holds one element in each row. df[condition] keeps the rows where the condition is true; join conditions with &, each in brackets. sort_values("col", ascending=False) sorts from largest to smallest. set_index("symbol").loc[row, col] looks up one value. A computed column is one line, such as df["ie_eV"] = df["ie"] / 96.49.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The first line. The column is radius, all small letters. df["Radius"] stops with KeyError: 'Radius'. Fix: print(df["radius"].max()).
Step 2. The second line. and asks for one True or False, but each condition is a whole column. Python stops with ValueError: The truth value of a Series is ambiguous. Fix: print(df[(df["block"] == "s") & (df["ie"] > 500)]).
Answer: a KeyError from the capital R, and a ValueError from and; use radius and &.
Log in to join the discussion.
Loading…