import requests
html_dir = r"http://www.nmc.cn/publish/weather-bulletin/index.htm"
html_res = requests. get( html_dir)
html_res. status_code
if html_res. status_code == 200 :
print ( html_res. content)
from bs4 import BeautifulSoup
dir ( BeautifulSoup)
html_info = BeautifulSoup( html_res. content, "html.parser" )
html_info
type ( html_info)
html_info. find_all( "p" )
html_info. find_all( "b" )
for info in html_info. find_all( "b" ) :
print ( info)
print ( str ( info) [ 3 : - 4 ] )
with open ( "C:/Users/Jay/Desktop/test.txt" , "w" ) as out_file:
for info in html_info. find_all( "b" ) :
print ( info)
out_file. write( str ( info) [ 3 : - 4 ] + "\n" )
import plotly. express as px
df = px. data. iris( )
df
df. dtypes
df_select = df. loc[ : , [ 'sepal_length' , 'sepal_width' , 'petal_length' , 'petal_width' ] ]
df_select. head( )
import seaborn as sns
sns. pairplot( data = df_select)
PCA_function = PCA( n_components = 4 )
PCA_res = PCA_function. fit_transform( df_select)
type ( PCA_res)
PCA_res. shape
PCA_res
x = np. arange( 1 , 5 )
y = PCA_function. explained_variance_ratio_
plt. plot( x, y, '-o' )
plt. xlabel( "PC index" )
plt. ylabel( "PC explained variance ratio" )
plt. grid( )
plt. show( )
df_pca_res = pd. DataFrame( data = PCA_res[ : , : 2 ] , columns= [ 'PC1' , 'PC2' ] )
df_pca_res_add_name = pd. concat( [ df_pca_res, df[ [ 'species' ] ] ] , axis = 1 )
df_pca_res_add_name. head( )
sns. set_style( 'whitegrid' )
sns_plot_res = sns. scatterplot( data = df_pca_res_add_name, x = 'PC1' , y = 'PC2' , hue = 'species' )
sns_plot_res. figure. savefig( "C:/Users/Jay/Desktop/test.pdf" )