In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Numpy to analyze the proportion of all kinds of users", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Numpy to analyze the proportion of all kinds of users.
Analysis target
Looking at the last data, some of the data have two user categories: member and non-member.
This time we mainly analyze the proportion of two categories of users in the data.
Data reading and data cleaning
According to the process diagram, we mainly follow the following steps:
The code here is:
# data reading, data cleaning
Def read_clean_data ():
Clndata_arr_list = []
For data_filename in data_filenames:
File = os.path.join (data_path, data_filename)
Data_arr = np.loadtxt (file, skiprows=1, delimiter=',', dtype=bytes) .astype (str)
Cln_arr = np.core.defchararray.replace (data_arr [:,-1],'",'')
Cln_arr = cln_arr.reshape (- 1)
Clndata_arr_list.append (cln_arr)
Year_cln_arr = np.concatenate (clndata_arr_list)
Return year_cln_arr
There are two points to note here:
Because the data is large, we do not have the specific amount of data in the data file, so when using numpy.reshape, we can use numpy.reshape (- 1 numpy 1) so that numpy can replace-1 with the specific value after statistics.
Our need for data is no longer to get the average time, but to take the last column of the data and stack it together using the concatenate method for the next step.
Data analysis
According to the goal of this analysis, we take out the last column of Member type.
In the previous step, we have obtained all the values, in this part, we only need to screen out the values of members and non-members.
We can first take a look at this part of the code after completion:
# data analysis
Def mean_data (year_cln_arr):
Member = year_cln_ ar [year _ cln_arr = = 'Member'] .shape [0]
Casual = year_cln_ ar [year _ cln_arr = = 'Casual'] .shape [0]
Users = [member,casual]
Print (users)
Return users
Again, numpy.shape is used here to get the specific data of the user classification.
Result display
The generated pie chart:
Here is the code to generate the pie chart:
# result display
Plt.figure ()
Plt.pie (users, labels= ['Member',' Casual'], autopct='%.2f%%', shadow=True, explode= (0.05,0))
Plt.axis ('equal')
Plt.tight_layout ()
Plt.savefig (os.path.join (output_path,'. / piechart.png'))
Plt.show ()
At this point, I believe you have a deeper understanding of "how to use Numpy to analyze the proportion of all kinds of users". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.