I have a dataframe with the following form
And I would like to get the value for a particular column. For this I use .loc
but I'm wrong. Can you please help me?
import pandas as pd
data = pd.read_csv('data/marcas.csv')
marcas = pd.DataFrame(data)
print(marcas.loc[1, 'pull ups'])
If I make a print
mark it works fine but if I want to see a specific column it fails.
In your case it is not working for you because you have put a 1, so that would return the second row after the headers, and since there is only one row, it fails. Putting a 0 should do fine:
If what you want is to see the entire column, you can try like this:
And another way if you want to access a specific row of that column could be like this:
Just like in your case, putting [0] would give you the first row, putting [1] would return the second, etc.
To see a column in pandas you have to put the name of the dataframe and the name of the column in square brackets, in your case it would be like this:
As you can see, Python and Pandas offer us multiple and different ways to access the data of a DataFrame quickly and easily (here I have only left you a few), there are dozens of slicing and indexing techniques, it's a world.