In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about the case study of Python data visualization. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Preface
Three steps:
Determine the problem, select the drawing
Convert data, apply function
Parameter setting is clear at a glance
First of all, the period of time is analyzed.
The first step
Ask the question: the total amount of rental corresponds to the changing trend of humidity
Suitable for graphics: because humidity is a continuous numerical variable, we can choose a line chart to reflect the changing trend.
Step two
Conversion data: we need a two-dimensional data box, sorted according to temperature changes, and take the average of the corresponding three leases
Application function: the line chart can be completed by directly applying the plot function of plt
Workingday_df = Bikedata [Bikedata ['workingday'] = = 1] # tworkingday_df = workingday_df.groupby ([' hour'], as_index=True). Agg ({'count':'mean','registered':'mean','casual':'mean'}) nworkingday_df = Bikedata [Bikedata [' workingday'] = 0] nworkingday_df = nworkingday_df.groupby (['hour'], as_index=True). Agg ({' count':'mean','registered':'mean') 'casual':'mean'}) nworkingday_df.head ()
Step 3: set parameters
Figure,axes = plt.subplots set up a 1x 2 canvas and share the y axis workingday _ df.plot (figsize= (15mine5), title='The average number of rentals initiated per hour in the workingday', ax=axes [0]) nworkingday_df.plot (figsize= (15recover5), title='The average number of rentals initiated per hour in the nworkingday', ax=axes [1])
As can be seen:
On weekdays, members travel corresponds to two obvious morning and evening peak periods, and there will be a small peak at noon, which may correspond to the demand for lunch out.
The peak travel time for non-member users on weekdays is about 3: 00 p.m.
Members travel far more than non-member users on weekdays.
On weekends, the overall travel trend is the same, with most car use taking place between 11: 00 and 5: 00, with the most at 5: 00 in the morning.
Analyze the temperature
The first step
Ask the question: the total amount of rental corresponds to the changing trend of humidity
Suitable for graphics: because humidity is a continuous numerical variable, we can choose a line chart to reflect the changing trend.
Step two
Conversion data: we need a two-dimensional data box, sorted according to temperature changes, and take the average of the corresponding three leases
Application function: the line chart can be completed by directly applying the plot function of plt
Step three
Parameter setting: only need to set the title of the line chart, other parameters default
Temp_df = Bikedata.groupby (['temp'], as_index='True') .agg ({' count':'mean','registered':'mean','casual':'mean'}) temp_df.plot (title = 'The average number of rentals initiated per hour changes with the temperature')
With the increase of temperature, the number of leases shows an upward trend.
When the temperature reaches 35 degrees, the overall number begins to decline because of the hot weather.
When the temperature is 4 degrees, the number of leases reaches the lowest point.
The influence of humidity on the number of leases
The first step
Ask the question: the total amount of rental corresponds to the changing trend of humidity
Suitable for graphics: because humidity is a continuous numerical variable, we can choose a line chart to reflect the changing trend.
Step two
Conversion data: we need a two-dimensional data box, sorted according to temperature changes, and take the average of the corresponding three leases
Application function: the line chart can be completed by directly applying the plot function of plt
Step three
Parameter setting: only need to set the title of the line chart, other parameters default
Humidity_df = Bikedata.groupby (['humidity'], as_index=True) .agg ({' count':'mean','registered':'mean','casual':'mean'}) humidity_df.plot (title='Average number of rentals initiated per hour in different humidity')
It can be observed that the number of rentals quickly reached a peak at about 20 humidity, and then decreased slowly.
The mapping methods of year, month and season are similar, they are all drawn by line chart, which is omitted here.
Check the impact of different weather on travel
The first step
Ask the question: the total amount of rental corresponds to the changing trend of humidity
Suitable for graphics: because the weather condition is a numerical classification variable, we can choose a column chart to observe the quantity distribution.
Step two
Convert data: we need a two-dimensional data box to average the number of leases according to the weather
Application function: using the plot.bar function of plt to draw a combined column chart
Step three
Parameter setting: only need to set the title of the line chart, other parameters default
Weather_df = Bikedata.groupby (['weather'], as_index=True) .agg ({' registered':'mean','casual':'mean'}) weather_df.plot.bar (stacked=True,title='Average number of rentals initiated per hour in different weather')
It is observed that when the weather level is 4, the average number of travelers is higher than the weather grade 2, which is not in line with common sense.
Let's check the details of the weather level 4.
Count_weather = Bikedata.groupby ('weather') count_weather [[' casual','registered','count']] .count ()
The time is 06:00 in the afternoon of the working day, which belongs to the abnormal data of the evening peak and is not representative.
Member users and temporary users account for the proportion of total users
The first step
Ask a question: check the proportion of member users and temporary users in the total user
Suitable for graphics: view proportion, suitable for pie chart pie
Step two
Convert data: need a two-dimensional data box to take the average of two kinds of users according to the number of days
Application function: use the plot.pie function of plt to draw pie chart
Step three
Parameter settings: this is the data label and category label
# considering whether the information such as working day, day of the week, and year are the same on the same date, sum the rental data by day Take the average of other date data day_df = Bikedata.groupby (['date'], as_index=False). Agg ({' casual':'sum','registered':'sum','count':'sum', 'workingday':'mean','weekday':'mean','holiday':'mean','year':'mean'}) day_df.head ()
# take the daily average of two types of users number_pei=day_df [['casual','registered']] .mean () number_peicasual 517.411765registered 2171.067031dtype: float64# to draw pie charts plt.axes (aspect='equal') plt.pie (number_pei, labels= [' casual','registered'], autopct='%1.1f%%', pctdistance=0.6, labeldistance=1.05, radius=1) plt.title ('Casual or registered in the total lease') Text (0.5)
Thank you for reading! This is the end of this article on "case Analysis of Python data Visualization". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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: 297
*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.