Skip to content

Instantly share code, notes, and snippets.

@ljak
Created July 21, 2020 23:35
Show Gist options
  • Save ljak/cfcb668544d16ad52fdc0b58c99b4e84 to your computer and use it in GitHub Desktop.
Save ljak/cfcb668544d16ad52fdc0b58c99b4e84 to your computer and use it in GitHub Desktop.
Pandas read CSV and prefix every row value with column name
df = pd.read_csv(WORKING_FOLDER + FILE, index_col=0)
# columns names = list(df.columns.values)
def prefix_every_row_with_column_name(column):
return column.name + " : " + column.astype(str)
df = df.apply(lambda column: prefix_every_row_with_column_name(column), axis=0) # axis=0 are the columns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment