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

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 :: hexdigest python 
Python :: take columns to rows in pandas 
Python :: python basic programs 
Python :: virtual environment python 
Python :: programação funcional python - lambda 
Python :: connect and disconnect event on socketio python 
Python :: get_permissions 
Python :: longest common prefix 
Python :: global var in python 
Python :: list insert python 
Python :: elif python 
Python :: euclidean distance 
Python :: Math Module cos() Function in python 
Python :: python any() function 
Python :: how to store the variable in dictionary 
Python :: Converting time python 
Python :: convert sentence to list of words python 
Python :: python online compiler 
Python :: how to access pandas column 
Python :: stack python 
Python :: python import statement 
Python :: TRY 
Python :: python variables and data types 
Python :: python - 
Python :: add items to list python 
Python :: why is c faster than python 
Python :: dfs algorithm python 
Python :: python get item from set 
Python :: firestore search query flutter 
Python :: crud python 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =