I’m trying to pull the same range from the same column two seperate ways (once through iloc on the number, and once through loc on the object name), and I’m thinking that the results should be identical – because its the same range from the same column. But its not printing out the same.
The raw data source (Palmer Penguins) is linked inside the code chunk below, so you can copy/paste and run the code on your end to check the column names, row values, etc – or – you can just review the results that I paste in below.
I’m trying to print the rows for penguins 8, 9, and 10 (note you’re seeing index place numbers in the output, not row numbers or values). And if I use the loc method for the column name, it gets me the three rows that I am looking for. But if I use the iloc method on the column number – then it only gets me the rows for penguins 8 and 9 – but not row 10 – it’s like it just ignores this part iof the request, which seems unambiguous.
My question is then: what am I missing, and why am I not getting row 10 if I use this latter iloc method on the column number?
I’ve tried two seperate IDEs and it prints out the same. Here is the code and the output below:
”’
import pandas as pd
penguins = pd.read_csv(‘https://gist.githubusercontent.com/slopp/ce3b90b9168f2f921784de84fa445651/raw/4ecf3041f0ed4913e7c230758733948bc561f434/penguins.csv’)
print(penguins.loc[7:9, [“bill_length_mm”]])
print(penguins.iloc[7:9, [3]])
”’
Output: %runfile C:/Users/rodkr/.spyder-py3/temp.py –wdir
bill_length_mm
7 39.2
8 34.1
9 42.0
bill_length_mm
7 39.2
8 34.1
THANKS!!
submitted by /u/MiracleNamedHope
[link] [comments]
r/learnpython I’m trying to pull the same range from the same column two seperate ways (once through iloc on the number, and once through loc on the object name), and I’m thinking that the results should be identical – because its the same range from the same column. But its not printing out the same. The raw data source (Palmer Penguins) is linked inside the code chunk below, so you can copy/paste and run the code on your end to check the column names, row values, etc – or – you can just review the results that I paste in below. I’m trying to print the rows for penguins 8, 9, and 10 (note you’re seeing index place numbers in the output, not row numbers or values). And if I use the loc method for the column name, it gets me the three rows that I am looking for. But if I use the iloc method on the column number – then it only gets me the rows for penguins 8 and 9 – but not row 10 – it’s like it just ignores this part iof the request, which seems unambiguous. My question is then: what am I missing, and why am I not getting row 10 if I use this latter iloc method on the column number? I’ve tried two seperate IDEs and it prints out the same. Here is the code and the output below: ”’ import pandas as pd penguins = pd.read_csv(‘https://gist.githubusercontent.com/slopp/ce3b90b9168f2f921784de84fa445651/raw/4ecf3041f0ed4913e7c230758733948bc561f434/penguins.csv’) print(penguins.loc[7:9, [“bill_length_mm”]]) print(penguins.iloc[7:9, [3]]) ”’ Output: %runfile C:/Users/rodkr/.spyder-py3/temp.py –wdir bill_length_mm 7 39.2 8 34.1 9 42.0 bill_length_mm 7 39.2 8 34.1 THANKS!! submitted by /u/MiracleNamedHope [link] [comments]
I’m trying to pull the same range from the same column two seperate ways (once through iloc on the number, and once through loc on the object name), and I’m thinking that the results should be identical – because its the same range from the same column. But its not printing out the same.
The raw data source (Palmer Penguins) is linked inside the code chunk below, so you can copy/paste and run the code on your end to check the column names, row values, etc – or – you can just review the results that I paste in below.
I’m trying to print the rows for penguins 8, 9, and 10 (note you’re seeing index place numbers in the output, not row numbers or values). And if I use the loc method for the column name, it gets me the three rows that I am looking for. But if I use the iloc method on the column number – then it only gets me the rows for penguins 8 and 9 – but not row 10 – it’s like it just ignores this part iof the request, which seems unambiguous.
My question is then: what am I missing, and why am I not getting row 10 if I use this latter iloc method on the column number?
I’ve tried two seperate IDEs and it prints out the same. Here is the code and the output below:
”’
import pandas as pd
penguins = pd.read_csv(‘https://gist.githubusercontent.com/slopp/ce3b90b9168f2f921784de84fa445651/raw/4ecf3041f0ed4913e7c230758733948bc561f434/penguins.csv’)
print(penguins.loc[7:9, [“bill_length_mm”]])
print(penguins.iloc[7:9, [3]])
”’
Output: %runfile C:/Users/rodkr/.spyder-py3/temp.py –wdir
bill_length_mm
7 39.2
8 34.1
9 42.0
bill_length_mm
7 39.2
8 34.1
THANKS!!
submitted by /u/MiracleNamedHope
[link] [comments]