要在 Pandas 中追加一行内容,可以使用 'append()' 方法。以下是一个示例:

import pandas as pd

# 创建一个空的 DataFrame
df = pd.DataFrame(columns=['Name', 'Age'])

# 创建要追加的行数据
new_row = {'Name': 'John', 'Age': 25}

# 使用 append() 方法追加行数据
df = df.append(new_row, ignore_index=True)

# 打印 DataFrame
print(df)

输出结果将是:

   Name  Age
0  John   25

在上述示例中,我们首先创建了一个空的 DataFrame,然后创建了要追加的行数据 'new_row'。接下来,我们使用 'append()' 方法将 'new_row' 追加到 DataFrame 中,并使用 'ignore_index=True' 参数重新索引 DataFrame。最后,我们打印了 DataFrame 以查看追加的行数据。

Pandas 追加数据行:使用 append() 方法

原文地址: https://www.cveoy.top/t/topic/fKc1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录