如何在python数据框中的列上编写和循环列表?

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 

或者,是否有其他方法可以执行上述转换而无需使用list非常感谢你。

henrywongkk

您可以重复列表,list * n其中n是重复的次数。然后将其分配给'Column N'数据框,例如:

import pandas as pd
list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

df = pd.DataFrame()
df['Column N'] = list * 5
print(df)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章