Created
July 21, 2020 23:35
-
-
Save ljak/cfcb668544d16ad52fdc0b58c99b4e84 to your computer and use it in GitHub Desktop.
Pandas read CSV and prefix every row value with column name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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