Answers for "set row as column names pandas"

2

make first row column names pandas

new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header #set the header row as the df header
Posted by: Guest on April-23-2020
1

r set column values as rownames in dataframe

# Basic syntax:
rownames(your_dataframe) <- your_dataframe[,1]
your_dataframe[,1] <- NULL

# Example usage:
# Say you have the following dataframe and want to set the values of 
# col1 as the rownames and then remove col1, here's how to do it
names	col1	col2	col3
1		A		1		5
2		B		2		4
3		C		3		3
4		D		4		2
5		E		5		1

rownames(your_dataframe) <- your_dataframe[,1]
your_dataframe[,1] <- NULL

# Which would produce:
names	col1	col2
A		1		5
B		2		4
C		3		3
D		4		2
E		5		1
Posted by: Guest on October-11-2020

Code answers related to "set row as column names pandas"

Python Answers by Framework

Browse Popular Code Answers by Language