热线电话:13121318867

登录
2019-06-18 阅读量: 474
如何在python中添加列

如何在python中添加列:

为了在Pandas DataFrame中添加列,我们可以将新列表声明为列并添加到现有Dataframe中。

# Import pandas package

import pandas as pd

# Define a dictionary containing Students data

data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],

'Height': [5.1, 6.2, 5.1, 5.2],

'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}

# Convert the dictionary into DataFrame

df = pd.DataFrame(data)

# Declare a list that is to be converted into a column

address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']

# Using 'Address' as the column name

# and equating it to the list

df['Address'] = address

# Observe the result

print(df)

42.0390
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子