In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Python how to achieve bicycle rental data analysis". In daily operation, I believe many people have doubts about how to achieve bicycle rental data analysis in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve bicycle rental data analysis in Python". Next, please follow the editor to study!
Data source
This section takes the bicycle rental data as an example, which comes from the network, uses the method of time series analysis and visualization technology to analyze the distribution of bicycle rental with time and weather, in which datetime, season, holiday, workingday, weather, temp, atemp, humidity, windspeed, casual, registered and count fields represent rental time, season, whether it is a holiday, whether it is a working day, and the larger the weather number is. The worse the weather, temp atemp temperature, humidity, wind speed, ordinary users, registered users, the number of rental bikes. Import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inline
Bike = pd.read_csv (open (rattd:\ python data Analysis\ data\ bike.csv')) bike.head ()
Problem exploration
Study the relationship between time period and bicycle rental.
Data cleaning
Bike.isnull () .sum ()
Check the missing values, no missing values. Bike.dtypes
To view the data type, the datetime field is not a time data type. Bike ['datetime'] = pd.to_datetime (bike [' datetime']) bike.dtypes
Convert the to_datetime function to datetime class data. Bike = bike.set_index ('datetime') # set the datetime field to the index of DataFrame and become the time series data bike.head ()
Bike.index # Index
Bike.tail ()
Data exploration
Y_bike = bike.groupby (lambda x: x.year). Mean () # downsampled year data y_bike ['count']
Y_bike ['count'] .plot (kind='bar') # plots a histogram
There are more rental data in 2012 than in 2011. M_bike = bike.resample ('Mises, kind='period'). Mean () # resample to month, type is period type
M_bike.head ()
Fig, axes = plt.subplots (2,1) # two rows and one column m_bike ['2011'] [' count'] .plot (ax=axes [0], sharex=True) # contribute X axis m_bike ['2012'] [' count'] .plot (ax=axes [1])
The trend in 2011 and 2012 is roughly the same, gradually increasing in the first few months, reaching a peak in May and June, and then gradually decreasing in September. Bike ['day'] = bike.index.daybike [' hour'] = bike.index.hour # separate storage of day and time data
Bike.head ()
D_bike = bike.groupby ('day') [' count'] .mean () # Group statistics for day fields
D_bike
D_bike.plot () # bicycle daily rental distribution
H_bike = bike.groupby ('hour') [' count'] .mean () # Group statistics for hour fields
H_bike
H_bike.plot () # bicycle rental per hour distribution
There are two obvious peaks in the picture, both during commuting hours, and the peak is even higher at night. Work_bike = bike.groupby ('workingday') [' count'] .mean ()
Work_bike # grouping statistics of workingday fields
Work_bike.plot (kind='bar')
The worse the weather, the less the number of bicycle rentals. Weather_bike = bike.groupby ('weather') [' count'] .mean ()
Weather_bike # grouping statistics of weather fields
Weather_bike.plot (kind='bar')
The worse the weather, the less the number of bicycle rentals, but there is a slight increase in extreme weather. At this point, the study on "how to achieve bicycle rental data analysis by Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.