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

How to create two variables columns

I try to recreate this :

Text

The main problem is that i have 160 users and 26 pages. And i need to add or remove ID or page ID sometimes. How can i do that with Python ?

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 see two separate problems, first to create it in Python and then to change it to "columns" like in Excel or CSV and i don’t know where to start ?

Expect that :

users = ["a", "b", "c"]
liste_page = []

for i in range(27):
    liste_page.append(i)

full = dict(zip(liste_page, users))

Thanks for your help

>Solution :

This should work for you I believe:

import pandas as pd
import itertools


a=tuple(map(lambda x:f'User {x}' ,list(range(1,161))))
b=range(1,27)

final_df = pd.DataFrame(list(itertools.product(a, b)), columns = ['ID', 'Page ID'])

final_df.to_csv('Final_output.csv', index=False)

Final output is:

print(final_df)

            ID  Page ID
0       User 1        1
1       User 1        2
2       User 1        3
3       User 1        4
4       User 1        5
...        ...      ...
4155  User 160       22
4156  User 160       23
4157  User 160       24
4158  User 160       25
4159  User 160       26

[4160 rows x 2 columns]
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