list = [a, b, c, d, e, f, g, h]
如何在 python 数据框中的特定列上编写并循环上述列表,以便结果...
数据框:
N 列(例如)
a
b
c
d
e
f
g
h
a
b
c
d
e
f
g
h
...
(many times)
...
a
b
c
d
e
f
g
h
或者,是否有其他方法可以在不需要使用列表
的情况下执行上述转换?非常感谢。
最佳答案
times
变量是您要重复的次数。请尝试以下操作:
import pandas as pd
letters = 'abcdefgh'
times = 4
df = pd.DataFrame({'Column Name': [x for x in letters]*times})
print(df)
或者这个:
import pandas as pd
from string import ascii_lowercase
times = 4
df = pd.DataFrame({'Column Name': [x for x in ascii_lowercase[:8]]*times})
print(df)
ascii_lowercase
返回字母表中的所有字母。
关于python - 如何在Python数据框中的列上编写和循环列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58445003/