Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas convert first row to header

df.rename(columns=df.iloc[0]).drop(df.index[0])
Comment

pandas convert header to first row

# best practice is to use the `header=None` parameter
# this way, the initial header will turn into the first row in the dataframe
df = pd.read_csv(file, header=None)
Comment

pandas convert first row to header

df, df.columns = df[1:] , df.iloc[0]
Comment

pandas convert first row to header

df = df.T.set_index(0).T
Comment

pandas convert first row to header

df.columns = df.iloc[0] 

df = df[1:]

df.head()
Comment

pandas first row to header

see the difference between these two lines
#no header
data= pd.read_csv(path, header = None, delim_whitespace=True, error_bad_lines=False)
#with headers
data= pd.read_csv(path, delim_whitespace=True, error_bad_lines=False)
Comment

PREVIOUS NEXT
Code Example
Python :: time date year python 
Python :: pandas merge df 
Python :: Returns the first n rows 
Python :: python assert is not null 
Python :: create an empty numpy array and append 
Python :: python find file name 
Python :: django only certain columns from database 
Python :: group by, aggregate multiple column -pandas 
Python :: zip python 
Python :: slicing in python listing 
Python :: match statement 
Python :: turtle star python 
Python :: how to make program speak in python 
Python :: python cli click 
Python :: get last 3 in array python 
Python :: scatter matrix plot 
Python :: find sum numbers in a list in python 
Python :: tensor.numpy() pytorch gpu 
Python :: python how to show package version 
Python :: python how to turn a word into a list 
Python :: bar plot bokeh 
Python :: how append a directory based on current directory python 
Python :: import class in python 
Python :: python while continue 
Python :: print random integers py 
Python :: get current function name in python3 
Python :: python check samplerate of mp3 
Python :: how to enter a int in python 
Python :: turtle keep window open 
Python :: checksum python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =