Horje
pandas slicing from one column to another Code Example
pandas slicing from one column to another
# slice from 'foo' to 'cat' by every 2nd column
df.loc[:, 'foo':'cat':2]
# foo quz cat

# slice from the beginning to 'bar'
df.loc[:, :'bar']
# foo bar

# slice from 'quz' to the end by 3
df.loc[:, 'quz'::3]
# quz sat

# attempt from 'sat' to 'bar'
df.loc[:, 'sat':'bar']
# no columns returned

# slice from 'sat' to 'bar'
df.loc[:, 'sat':'bar':-1]
sat cat ant quz bar

# slice notation is syntatic sugar for the slice function
# slice from 'quz' to the end by 2 with slice function
df.loc[:, slice('quz',None, 2)]
# quz cat dat

# select specific columns with a list
# select columns foo, bar and dat
df.loc[:, ['foo','bar','dat']]
# foo bar dat
python - row slice dataframe by number of rows
df.iloc[[1, 5]]                                               # Get rows 1 and 5
df.iloc[1:6]                                                  # Get rows 1 to 5 inclusive
df.iloc[[1, 5], df.columns.get_loc('Shop')]                   # Get only specific column
df.iloc[[1, 5], df.columns.get_indexer(['Shop', 'Category'])] # Get multiple columns




Python

Related
how to increment date by one in python Code Example how to increment date by one in python Code Example
No module named 'filterpy' Code Example No module named 'filterpy' Code Example
pandas normalize columns Code Example pandas normalize columns Code Example
clean punctuation from string python Code Example clean punctuation from string python Code Example
python boxplot show mean Code Example python boxplot show mean Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7