Python 在DataFrame增加一列相同的数值

星辰大海的路上 2020-02-13

生成一个 DataFrame

import pandas as pd

name = [‘Cindy‘,‘John‘,‘Matt‘]
point = [78,87,88]

df_grade = pd.DataFrame(name, columns=[‘name‘])
df_grade = pd.concat([df_grade, pd.DataFrame(point,columns=[‘point‘])],axis=1)

新增一列

df_grade[‘gender‘] = ‘male‘
print(df_grade)

结果

name  point gender
 Cindy     78   male
  John     87   male
  Matt     88   male

相关推荐