Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Generate table with predefined parameters

I want to create a table with these parameters:

        # Setting parameters for table
        initial_year=2020
        last_year=2030

        # Setting column names
       
         ## First two columns' names
        The first two columns must have columns with the names 'Wages' and 'Payment'
        
        ### Columns after the second column
        listName = ['column1','column2','column3','column4']

In the end, I need to have the table as the table below

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried this line of code, but is not working

df=pd.DataFrame(rows=range(initial_year,last_year)).add_prefix('Year')

Can anybody help me how to solve this problem and generate table as table above ?

>Solution :

You can use:

initial_year=2020
last_year=2030

cols = ['Wages', 'Payment']
listName = ['column1','column2','column3','column4']

df = (pd.DataFrame({'Year': range(initial_year, last_year+1)})
        .reindex(columns=['Year']+cols+listName, fill_value=1)
     )

print(df)

Output:

    Year  Wages  Payment  column1  column2  column3  column4
0   2020      1        1        1        1        1        1
1   2021      1        1        1        1        1        1
2   2022      1        1        1        1        1        1
3   2023      1        1        1        1        1        1
4   2024      1        1        1        1        1        1
5   2025      1        1        1        1        1        1
6   2026      1        1        1        1        1        1
7   2027      1        1        1        1        1        1
8   2028      1        1        1        1        1        1
9   2029      1        1        1        1        1        1
10  2030      1        1        1        1        1        1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading