Traceback (most recent call last):subset = df[[1]]
I am hope that pandas questions are OK here.
In a panda lecture, I did not get the expected result.
I tried this on two different platforms
(old macOS distro and up-to-date Ubuntu Linux distro, 22.04)
The Linux distro has:
python 3.10.11
pandas 1.5.2
conda 23.3.1
Is this double bracket form, df[[1]], deprecated... maybe?
There is data in a dataframe, df.
subset = df[[1]]
countrysubset = df[[0]]
print(subset.head())
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
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')
countrysubset = df[[0]]
print(subset.head())
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. :-)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 58:43:28 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,631 |