不易财经，财经笔记

Pandas 1

# Import all libraries needed for the tutorial# General syntax to import specific functions in a library: ##from (library) import (specific library function)frompandasimportDataFrame,read_csv# General syntax to import a library but no functions: ##import (library) as (give the library a nickname/alias)importmatplotlib.pyplotaspltimportpandasaspd#this is how I usually import pandasimportsys#only needed to determine Python version numberimportmatplotlib#only needed to determine Matplotlib version number# Enable inline plotting%matplotlib inline

print('Python version '+sys.version)print('Pandas version '+pd.__version__)print('Matplotlib version '+matplotlib.__version__)

# Create graphdf['Births'].plot()# Maximum value in the data setMaxValue=df['Births'].max()# Name associated with the maximum valueMaxName=df['Names'][df['Births']==df['Births'].max()].values# Text to display on graphText=str(MaxValue)+" - "+MaxName# Add text to graphplt.annotate(Text,xy=(1,MaxValue),xytext=(8,0),xycoords=('axes fraction','data'),textcoords='offset points')print("The most popular name")df[df['Births']==df['Births'].max()]#Sorted.head(1) can also be used