I have a pandas dataframe:
'' count
sugar 420
milk 108
vanilla 450
...
There is no heading in the first column, and I would like to name it: "component".
I created a dataframe from the csv file:
df = pd.read_csv('./data/file_name.csv', index_col=False, encoding="ISO-8859-1")
df = df['ingredient_group'] #selecting column
df = df.value_counts() #calculating string occurance which return series obj
df = pd.DataFrame(df) #creating dataframe from series obj
How do I give the name "ingredient" to the first column that currently doesn't have a name?
I already tried:
df_count.rename(columns={'': 'ingredient'}, inplace=True)
df = pd.DataFrame(df, columns = ['ingredient','count']
How can I prevent this?
'' count
ingredient ''
sugar 420
milk 108
vanilla 450
...
Papie source
share