get first column of dataframe pandas code example
Example 1: get only first 10 columns pandas
df.iloc[:, : 50]
Example 2: make first row column names pandas
new_header = df.iloc[0]
df = df[1:]
df.columns = new_header
Example 3: pandas print first column
df = pd.DataFrame({"Letters": ["a", "b", "c"], "Numbers": [1, 2, 3]})
first_column = df.iloc[:, 0]
Example 4: make first row column names pandas
df.rename(columns=df.iloc[0])
Example 5: make first row column names pandas
In [24]: df.drop(df.index[1])
Out[24]:
1 foo bar baz
0 1 2 3
2 4 5 6