pandas select column by index
# A B C
# 0 1 3 5
# 1 2 4 6
column_B = a_dataframe.iloc[:, 1]
print(column_B)
# OUTPUT
# 0 3
# 1 4
pandas select column by index
# A B C
# 0 1 3 5
# 1 2 4 6
column_B = a_dataframe.iloc[:, 1]
print(column_B)
# OUTPUT
# 0 3
# 1 4
isolate row based on index pandas
dfObj.iloc[: , [0, 2]]
select rows from dataframe pandas
from pandas import DataFrame
boxes = {'Color': ['Green','Green','Green','Blue','Blue','Red','Red','Red'],
'Shape': ['Rectangle','Rectangle','Square','Rectangle','Square','Square','Square','Rectangle'],
'Price': [10,15,5,5,10,15,15,5]
}
df = DataFrame(boxes, columns= ['Color','Shape','Price'])
select_color = df.loc[df['Color'] == 'Green']
print (select_color)
pandas column by index
DataFrame.iloc[:, n]
get column index pandas
df = pd.read_csv('thanksgiving_w_age_income.csv')
# Obtain Column Indices:
gravy = df.columns.get_loc("Do you typically have gravy?")
meet_friends = df.columns.get_loc('Have you ever tried to meet up with hometown friends on Thanksgiving night?')
friendsgiving = df.columns.get_loc('Have you ever attended a "Friendsgiving?"')
pandas df by row index
indices = [133, 22, 19, 203, 14, 1]
df_by_indices = df.iloc[indices, :]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us