Our Series # first create the object, and then merged into dataframe objects inside to Import PANDAS AS pd Import numpy AS NP
area=pd.Series({'ChongQing':188888,'BeiJing':92387928,'Shanghai':8374583746,'Sydney':82734}) population=pd.Series({'ChongQing':1000,'BeiJing':2000,'Shanghai':2900,'Sydney':3000}) datapd.DataFrame = ({ ' Area ' : Area, ' Population ' : Population}) # NOTE: Be sure to follow the dictionary data structure when creating the dictionary structure after # is finished creating the dictionary must be spent in a front-write the dictionary brackets, this is a very important habit print (data)
Output:
area population ChongQing 188888 1000 BeiJing 92387928 2000 Shanghai 8374583746 2900 Sydney 82734 3000
Enter the code on target to increase our colums:
data['area']
Output:
ChongQing 188888 BeiJing 92387928 Shanghai 8374583746 Sydney 82734 Name: area, dtype: int64
Input:
Utilizing # attribute to list a data columns, the above is used in the form of an index, and less common form of such
data.area
Output:
ChongQing 188888 BeiJing 92387928 Shanghai 8374583746 Sydney 82734 Name: area, dtype: int64
Input:
data.values # dataframe fact is very clear that a two-dimensional array, we can use this formula to verify it
Output:
array([[1.88888000e+05, 1.00000000e+03, 1.88888000e+02], [9.23879280e+07, 2.00000000e+03, 4.61939640e+04], [8.37458375e+09, 2.90000000e+03, 2.88778750e+06], [8.27340000e+04, 3.00000000e+03, 2.75780000e+01]])