【问题标题】:How can I concat two columns into one column in Python如何在 Python 中将两列合并为一列
【发布时间】:2020-11-08 18:21:45
【问题描述】:

我是 Python 新手。我有两个数据框,分别是 june_df 和 july_df。列是相同的,只是值不同。 Index 62 is the starting point of july_df. How can I concat the column('quantity'), and make it consistent(shown in red cicrles)

【问题讨论】:

  • 当你进入 StackOverflow 时有用的东西:你可以通过在这个 (`) 中包含一个字符串来格式化你的变量名(不过不要过度使用,每段最多 4 个)。另外,添加this 之类的链接,不要将整行作为链接。

标签: python pandas dataframe concat


【解决方案1】:

我建议将一个数据框中的 qunatity 列重命名为 quantity 列。如果你在拼接之前做,那之后就不会有任何问题了。

您可以像这样使用pandas.DataFrame.rename() 方法重命名列:

my_df = my_df.rename({'qunatity': 'quantity'}, axis=1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    相关资源
    最近更新 更多