subset of columns pandas code example

Example 1: python - subset specific columns name in a dataframe

columns = ['b', 'c']
df1 = pd.DataFrame(df, columns=columns)

Example 2: python: select specific columns in a data frame

df = df[["Column_Name1", "Column_Name2"]]

Example 3: select columns pandas

df1 = df.iloc[:,0:2] # Remember that Python does not slice inclusive of the ending index.

Example 4: pandas sub columns

|     Start      |       Intermediary       |        End        |
|       |        |            |             |         |         |
_________________________________________________________________
| s_lat | s_lng  |  i_lat     |  i_lng      | e_lat   | e_lng   |

mux = pd.MultiIndex.from_product([['Start','Intermediary','End'], ['lat','lng']])
df = pd.DataFrame(data, columns=mux)

Tags:

Sql Example