In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "which modules are commonly used in Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Catalogue
1. Random random module
2. Matplotlab.pyplot drawing module
3. Mpl_toolkits.mplot3d 3D drawing module
1. Random random module
Import random
Code = random.choice (stock_list) # randomly select elements from a list below are modules that I often use at present. In order to facilitate use, without special needs, I feel that each module is very in-depth study at the beginning, as long as I know some of the commonly used methods. Update at any time, please search and use.
Random random selection module:
Import randoma = [1, 2, 3, 4, 5] print (random.choice (a)) # randomly extract an element from the list code = random.choice (stock_list) # randomly select elements from a list
Os folder module:
Import os# sets the default file path os.chdir () os.chdir (pd.read_csv ('sz300001.csv') data') df = pd.read_csv ('sz300001.csv') print df
Program root address, os.pardir: parent directory parent directory
Root_path = os.path.abspath (os.path.join (current_file, os.pardir, os.pardir)) # two-level parent directory print root_path
Enter the data root directory address
Input_data_path = os.path.abspath (os.path.join (root_path, 'data',' input_data'))
Time time module:
Import time
Get the current date
Date_now = time.strftime ('% Ymuri% mmury% dwells, time.localtime (time.time ()
timer
Start = time.time () end = time.time () used_time = str (end-start) print "used_time:" + used_time2, matplotlab.pyplot drawing module import matplotlib.pyplot as plt
Add a blank canvas
Fig = plt.figure (figsize= (12pm 5))
Set an area on a blank canvas
Ax = fig.add_subplot (1pm 1pm 1)
Set the title of the block
Ax.set_title (str (code)) ax.set_xlabel ('Time') # sets the name of the Abscissa x axis ax.set_ylabel (' Return') # sets the Y axis
Draw a 2D diagram and set the name to 'stock_return'
Plt.plot (df [equity], label='stock_return')
Draw scatter plot
Plt.scatter (df ['ma_long'], df [' final_ratio'], label='ma_long')
There are more graphics to draw. If you really need it, you can search again on the Internet.
Plt.legend (loc='best') # display the name of the graph line plt.show () # draw the image result 3, mpl_toolkits.mplot3d draw 3D picture module from mpl_toolkits.mplot3d import Axes3Dfig = plt.figure () ax = Axes3D (fig) ax.scatter (df ['ma_long'], df [' ma_short'], df ['final_ratio'] Drawing data points # setting the name of the axis ax.set_zlabel ('final_ratio') # axis ax.set_ylabel (' ma_short') ax.set_xlabel ('ma_long') plt.show () "what are the modules commonly used in Python" that ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.