简体   繁体   中英

how to transform a itertools.permutations to a dataframe in ptyhon?

I need to change a itertools.permutations into a format that i can use, such a dataframe or list, is possible to create a dataframe with itertools.permutations

how to transform a itertools.permutations to a dataframe in ptyhon?

from itertools import permutations 
perm_5 = permutations(alphabet, 5)

No idea what can i do with a itertools.permutations it give the permutation but for some reason in the tutorials only show how to print, and i need it to save it in a dataframe

Try

from itertools import permutations 
import pandas as pd

perm_5 = permutations(alphabet, 5)
df = pd.Dataframe(list(perm_5))

Or as suggested in comments by @sj95126,

pd.DataFrame({"perm":perm_5})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM