Pass the name of the dataframe into each for row for a new column in a list of dataframes Python

Issue

This Content is from Stack Overflow. Question asked by Spooked

I have a list of dataframes, I want to add a new column to each dataframe that is the name of the dataframe.

df_all = [df1,df2,df3]

for df in df_all:
    df["Loc"] = df[df].astype.(str)

Boolean array expected for the condition, not object

is this possible to achieve?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?