Document of Dictionaries
Ten Minutes to Pandas
Creation of Series and DataFrame
ImportPandas as PDImportNumPy as NPImportMatplotlib.pyplot as Plts= PD. Series ([1, 2, 5, Np.nan, 6, 8])#An array similar to NumPy is just one dimension, one dimension only#print (s)#0 1.0#1 2.0#2 5.0#3 NaN # Not a number means infinity or non-numeric#4 6.0#5 8.0#Dtype:float64dates= Pd.date_range ('20180116', periods=3)#Create 16 17 18, etc. 3 dates, and later as lineDF= PD. DataFrame (Np.random.randn (3,4), Index=dates, Columns=list ('ABCD'))#This is a two-dimensional, similar to a table! #by NumPy randomly a 3 * 4 data, which corresponds to the number of rows and columns#print (DF)#A B C D#2018-01-16-0.139759 0.857653 0.754470 0.224313#2018-01-17 1.565070 0.521973-1.265168-0.278524#2018-01-18-0.668574-0.527155 0.877785-1.123334#The DataFrame can also be created directly through a dictionary. DF2 = PD. DataFrame ({'A': 1., 'B': PD. Timestamp ('20130102'), 'C': PD. Series (1,index=list (range (4)), dtype='float32'), 'D': Np.array ([3] * 4,dtype='Int32'), 'E': PD. Categorical (["Test","Train","Test","Train"]), 'F':'Foo' })#print (DF2)#A B C D E F#0 1.0 2013-01-02 1.0 3 Test foo#1 1.0 2013-01-02 1.0 3 train foo#2 1.0 2013-01-02 1.0 3 Test foo#3 1.0 2013-01-02 1.0 3 train foo#get a specific type#print (df2.dtypes)#A float64#B Datetime64[ns]#C float32#D Int32#category E#F Object#Dtype:object
Python Notes #12 # Dictionary & Pandas:object Creation