On 03May2023 17:52, Artie Ziff <artie.z...@gmail.com> wrote:
The code came from a video course, "Pandas Data Analysis with Python
Fundamentals" by Daniel Chen.
I am curious why the author may have said this. To avoid attaching
screenshots, I'll describe this section of the content. Perhaps someone can
say, "oh that's how it used to work"... haha
Unlikely; Python indices (and by implication Pandas indices) have
counted from 0 since forever. I suspect just a typo/braino.
D.CHEN:
"You can also subset the columns by number. If we wanted to get the first
column from our data set, we would use zero":
df = pandas.read_csv('./data/gapminder.tsv', sep='\t')
subset = df[[0]]
print(subset.head())
country
0 Afghanistan
1 Afghanistan
2 Afghanistan
3 Afghanistan
4 Afghanistan
Data for the course:
https://github.com/chendaniely/pandas_for_everyone.git
"df[[0]]" is being described to the course student as selecting the first
column of data. :-)
Well, I would say it makes a new dataframe with just the first column.
So:
df[ 0 ] # spaces for clarity
would (probably, need to check) return the Series for the first column.
versus:
df[ [0] ] # spaces for clarity
makes a new dataframe with only the first column.
A dataframe can be thought of as an array of Series (one per column).
Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list