Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas select row by index

#for single row
df.loc[ index , : ]

# for multiple rows
indices = [1, 20, 33, 47, 52 ]
new_df= df.iloc[indices, :]
Comment

pandas select a row

#select the first row 
df.iloc[1]
#select the first row and return the value in column ['Biologie']
candidate_df.iloc[1]['Biologie']
Comment

pandas df by row index

indices = [133, 22, 19, 203, 14, 1]
df_by_indices = df.iloc[indices, :]
Comment

dataframe select row by index value

In [1]: df = pd.DataFrame(np.random.rand(5,2),index=range(0,10,2),columns=list('AB'))

In [2]: df
Out[2]: 
          A         B
0  1.068932 -0.794307
2 -0.470056  1.192211
4 -0.284561  0.756029
6  1.037563 -0.267820
8 -0.538478 -0.800654

In [5]: df.iloc[[2]]
Out[5]: 
          A         B
4 -0.284561  0.756029

In [6]: df.loc[[2]]
Out[6]: 
          A         B
2 -0.470056  1.192211
Comment

PREVIOUS NEXT
Code Example
Python :: python custom array sort 
Python :: datetime python timezone 
Python :: seasonal_decompose python 
Python :: python requests token x-www-form-urlencoded 
Python :: ValueError: logits and labels must have the same shape ((None, 1) vs (None, 2)) 
Python :: how to get the index of a value in pandas dataframe 
Python :: matplotlib remove y axis label 
Python :: only include top ten items django for loop 
Python :: Make solutions faster in python 
Python :: hot to pay music in pygame 
Python :: robot append to list with for loop 
Python :: combining list of list to single list python 
Python :: how to check for duplicates in a column in python 
Python :: ubuntu install pip for python 3.8 
Python :: python tkinter filedialog 
Python :: how to obtain the content of brackets 
Python :: python code to wait 
Python :: how to check if a proxy is dead in python 
Python :: how to visualize decision tree in python 
Python :: python convert datetime.timedelta into seconds 
Python :: random element python 
Python :: remove warnings from jupter notebook 
Python :: take off character in python string 
Python :: how to save a dictionary as a file in python 
Python :: python change base function 
Python :: jupyter nbextension 
Python :: transparancy argument pyplot 
Python :: pygame doesnt dedect collision between sprite and image 
Python :: python string exclude non alphabetical characters 
Python :: python working directory executed file 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =