I want to add a new column, Category, in each of my 8 similar dataframes.
The values in this column are the same, they are also the df name, like df1_p8 in this example.
I have used:
In: df61_p8.insert(3,"Category","df61_p8", True)
# or simply, df61_p8['Category']='df61_p8'
Out:
code violation_description Category
89491 9-1-503 Defective or obstructed duct system one- building df61_p8
102045 9-1-503 Defective or obstructed duct system one- building df61_p8
103369 9-1-503 Defective or obstructed duct system one- building df61_p8
130440 9-1-502 Failure to maintain at least one (1) elevator df61_p8
132446 9-1-503 Defective or obstructed duct system one- building df61_p8
Ultimately, I want to append/concat these 8 dataframes into one dataframe.
I wonder if there is more efficient way to do it, rather than using .insert one by one on each dataframe. Something like loops or lambdas.. As a beginner, I am not sure how to apply them in my case? thank you.
append_alldfs = []
x=[df61_p1,df61_p2,df61_p3,df61_p4,df61_p5,df61_p6,df61_p7,df61_p8]
lambdafunc = lambda x: x.insert(3,"Category","x",True)