Pandas Cookbook "1"

Source: Internet
Author: User

Online see about the use of pandas, although practiced a lot, but still some can not remember very clearly. So it was written down.

Chapter1 is talking about reading a CSV file. The following code:

1 #%%2 ImportPandas as PD3 ImportNumPy as NP4 ImportMatplotlib.pyplot as Plt5 #Make the graphs a bit prettier6Pd.set_option ('Display.mpl_style','default')7plt.rcparams['figure.figsize'] = (15,5)8 9 #%%TenBROKEN_DF = Pd.read_csv ('C:\Users\rui\Desktop\pandas-cookbook-master\data\bikes.csv') One #Look at the first 3rows;

There is no in-depth understanding of the use of read_csv. The next article will be a special explanation.

 1  fixed_df = pd.read_csv ( " c:\users\rui\desktop\pandas-cookbook-master\data\bikes.csv   ,  2  sep= " ;  ", Encoding="   Latinl  , Parse_dates=["  date   "],dayfirst=true,index_col=date   ") 

where Sep represents the delimiter, encoding is the specified encoding, and if the file contains non--ASCII character fields, ensure that it is read in the correct encoding. This is a major problem in reading Latin-1 files inside the UTF-8 Local system. At this point, you can handle the following. For parameters Parse_date:if True then index would be parsed as dates (False by default). Can specify more complicated options to parse a subset of columns or a combination of columns into a single date colum N (List of ints or names, list of lists, or dict) [1, 2,3];

Dayfirst:boolean, default False//dd/mm format dates, international and European format;

Index_col:int or sequence or False, default None

Column to use as the row labels of the DataFrame. If a sequence is given, a multiindex is used. If you had a malformed file with delimiters at the end of each line, you might consider Index_col=false to Forc E Pandas to _not_ use the first column as the index (row names)

1 fixed_df['Berri 1'].plot () 2 fixed_df.plot ( Figsize= (15,5))

Where the plot function does not draw the same Berri 1 data as in the original document. The reasons are currently being sought;

Pandas Cookbook "1"

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.