piper.verbs.rows_to_names¶
-
piper.verbs.rows_to_names(df: pandas.core.frame.DataFrame, start: int = 0, end: int = 1, delimitter: str = ' ', fillna: bool = False, infer_objects: bool = True) → pandas.core.frame.DataFrame[source]¶ promote row(s) to column name(s)
Optionally, infers remaining data column data types.
Examples
data = {'A': ['Customer', 'id', 48015346, 49512432], 'B': ['Order', 'Number', 'DE-12345', 'FR-12346'], 'C': [np.nan, 'Qty', 10, 40], 'D': ['Item', 'Number', 'SW-10-2134', 'YH-22-2030'], 'E': [np.nan, 'Description', 'Screwdriver Set', 'Workbench']} df = pd.DataFrame(data) head(df, tablefmt='plain') A B C D E 0 Customer Order nan Item nan 1 id Number Qty Number Description 2 48015346 DE-12345 10 SW-10-2134 Screwdriver Set 3 49512432 FR-12346 40 YH-22-2030 Workbench
df = rows_to_names(df, fillna=True) head(df, tablefmt='plain') Customer Id Order Number Order Qty Item Number Item Description 2 48015346 DE-12345 10 SW-10-2134 Screwdriver Set 3 49512432 FR-12346 40 YH-22-2030 Workbench
- Parameters
df – dataframe
start – starting row - default 0
end – ending row to combine, - default 1
delimitter – character to be used to ‘join’ row values together. default is ‘ ‘
fillna – default False. If True, fill nan values in header row.
infer_objects – default True. Infer data type of resultant dataframe
- Returns
- Return type
A pandas dataframe