mission details
Tasks for this level: According to the programming requirements, complete the writing of relevant codes.
related information
DataFrame
It is a tabular data structure, which is a data table (hierarchical index) stored in one or more two-dimensional blocks. It DataFrame
has both row index and column index. It has a set of ordered columns. Each column can be different Data of type (numeric, string, boolean), or can be viewed as Series
a dictionary composed of. DataFrame creation:
dictionary = {'state':['0hio','0hio','0hio','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002],
'pop':[1.5,1.7,3.6,2.4,2.9]}
frame = DataFrame(dictionary)
Modify row name:
frame=DataFrame(dictionary,index=['one','two','three','four','five'])
Add modifications:
frame['add']=[0,0,0,0,0]
Add Series type:
value = Series([1,3,1,4,6,8],index = [0,1,2,3,4,5])
frame['add1'] = value
Programming requirements
Follow the prompts and add code in the editor on the right begin-end
:
-
Create an array named with five rows and three columns, with column names
df1
and row names ;DataFrame
[states,years,pops]
['one','two','three','four','five']
-
Add
df1
a new column with a column namenew_add
and a value of[7,4,5,8,2]
.
Test instruction
If the answer is correct, it will be output True
.
# -*- coding: utf-8 -*-
from pandas import Series,DataFrame
import pandas as pd
def create_dataframe():
'''
返回值:
df1: 一个DataFrame类型数据
'''
# 请在此添加代码 完成本关任务
# ********** Begin *********#
df1 = pd.DataFrame(columns = ['states','years','pops'],index = ['one','two','three','four','five'])
df1['new_add'] = [7,4,5,8,2]
# ********** End **********#
#返回df1
return df1