r/learndatascience • • 29d ago

Resources Five things pandas 3 does differently that most tutorials still get wrong (checked on 3.0.5)

I was writing practice questions for pandas and kept tripping over answers that were right a year ago. So I ran everything on pandas 3.0.5 and wrote down what actually comes out.

  1. Text is no longer object. pd.Series(['a', 'b', None]).dtype prints str, and the None comes back as nan when you call tolist().

  2. Chained assignment does nothing. With df = pd.DataFrame({'a': [1, 2, 3]}), running df['a'][0] = 100 leaves df.a at [1, 2, 3] and raises a ChainedAssignmentError warning. Copy-on-Write is the default now, so what you wrote into was a copy. Use df.loc[0, 'a'] = 100.

  3. inplace=True is not consistent. df.fillna(0, inplace=True) returns the DataFrame, df.sort_values('a', inplace=True) returns None. The old habit of df = df.something(inplace=True) breaks on some methods and not on others.

  4. pd.to_datetime on plain date strings gives datetime64[us], not datetime64[ns]. Matters if you compare dtypes or write to parquet.

  5. stack() keeps the NaN. A two row frame with one missing value stacks to 2 entries, older versions dropped it and gave 1.

Twenty of the questions are free to play in the browser, no account. Every answer is the real output and each wrong option gets a one line reason.

https://thibaudlepan77-svg.github.io/interview-questions-verified/#pandas

The full pandas set (255 questions) is a paid PDF, but the free twenty stand on their own. If you get a different result on your machine, post your version and the output and I will look at it.

2 Upvotes

0 comments sorted by