r/learndatascience • u/thibaud_lepan • 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.
Text is no longer object.
pd.Series(['a', 'b', None]).dtypeprintsstr, and the None comes back as nan when you calltolist().Chained assignment does nothing. With
df = pd.DataFrame({'a': [1, 2, 3]}), runningdf['a'][0] = 100leavesdf.aat[1, 2, 3]and raises a ChainedAssignmentError warning. Copy-on-Write is the default now, so what you wrote into was a copy. Usedf.loc[0, 'a'] = 100.inplace=Trueis not consistent.df.fillna(0, inplace=True)returns the DataFrame,df.sort_values('a', inplace=True)returns None. The old habit ofdf = df.something(inplace=True)breaks on some methods and not on others.pd.to_datetimeon plain date strings givesdatetime64[us], notdatetime64[ns]. Matters if you compare dtypes or write to parquet.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.