Python Notes #12 # Dictionary & Pandas:object Creation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.