Aug-05-2024, 03:17 AM
(This post was last modified: Aug-05-2024, 05:45 AM by Gribouillis.)
I have a list of dataframes:
Thanks!
data1 = {'rec_number': [1, 2, ,3 ,4, 5, 6]} data2 = {'rec_number': [1, 2, ,3 ,4, 5, 6, 7, 8]} data3 = {'rec_number': [1, 2, ,3 ,4]} df1 = pd.DataFrame(data1) df2 = pd.DataFrame(data2) df3 = pd.DataFrame(data3) lst = [df1, df2, df3]My list would have thousands of dataframes, each having different 'rec_number', I need to add additional columns to all the dataframes to create a "shift like" columns. (take df1 for example):
data1 = {'rec_number': [1, 2, ,3 ,4, 5, 6], 'rec_number_2': [np.nan, 1, 2, 3, 4, 5], 'rec_number_3': [np.nan, np.nan, 1, 2, 3, 4], 'rec_number_4': [np.nan, np.nan, np.nan, 1, 2, 3], 'rec_number_5': [np.nan, np.nan, np.nan, np.nan, 1, 2], 'rec_number_6': [np.nan, np.nan, np.nan, np.nan, np.nan, 1]} df1 = pd.DataFrame(data1)What would be most efficient way to add those additional columns?
Thanks!
Gribouillis write Aug-05-2024, 05:45 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.