【问题标题】:How to append more data in a column without overriding如何在不覆盖的情况下在列中附加更多数据
【发布时间】:2022-12-15 06:17:06
【问题描述】:

您好,我想在一列中添加一些数据,这样我就有了一个列表,我想在列表大小大于 M(其中 M 是行数)的时候从中选择数据。如果它大于 M 它应该迭代并附加数据并用逗号 [,] 分隔数据但不覆盖它如果小于它应该跳过其余数据或添加空数据。我也在创建列运行时间

def read_tor_cell(self):
    queue = ['a','b','c','a','b','c']
        complete_path = self.Task2 + filename
        print(complete_path)
        for i in queue():
            df_round_robin = self.path_to_csv.head(M)
            df_round_robin["new_column"] = i
            df_round_robin.to_csv('test.csv')
            print(df_round_robin)


Output:: Assume m=2
for row 1:: inside new_column a,c,b
for row 2:: inside new_column b,a,c

m=3
for row 1:: inside new_column a,a
for row 2:: inside new_column b,b
for row 3:: inside new_column c,c

【问题讨论】:

  • 什么是预期的输出?

标签: python python-3.x pandas dataframe


【解决方案1】:

如果您想将队列添加为新列,您只需要:

df_round_robin["new_column"] = queue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 2018-04-06
    相关资源
    最近更新 更多