Visual Analysis of Campus Card Consumption Data based on Matplotlib

: This paper selected the consumption data derived from the student campus card of the School of Management Science and Engineering of Anhui University of Finance and Economics as the research object. Initially, data cleansing and classification were conducted using Python and Excel. Subsequently, the Matplotlib library was utilized to visually analyze both overall data of student consumption and the dining data with its higher proportion. Through the in-depth study of the campus card data, a thorough understanding of students’ dining patterns was achieved. Furthermore, the study recorded fluctuations in cafeteria footfall at various times of the day, providing valuable reference for optimizing resources and informing management decision-making regarding the school canteen from multiple perspectives.


Introduction
As an integral component of the "Smart Campus" construction, the campus card, known as "One Card," has provided significant convenience for students' on-campus consumption and daily lives. Over time, the campus card has stored a vast amount of data regarding their consumption and behavioral patterns while on campus. Leveraging scientific data processing and analysis methods, the analysis and modeling of this complex and diverse dataset can uncover latent value. Such analysis will aid school administrators in understanding students' consumption habits and behavioral patterns, facilitating a more rational optimization of school resource allocation and enabling sensible decision-making.

Data Source and Structure
This paper examines the consumption data extracted from the student campus card system at the School of Management Science and Engineering of Anhui University of Finance and Economics. The data covers a period from April 2022 to April 2023, encompassing a total of 1,141,247 recorded items. The reasons for selecting data from this period are as follows: firstly, it includes both winter and summer vacations, allowing for a comparison of spending behavior during school time versus vacation periods. This comparison can shed light on potential variations in consumption patterns; secondly, the selected timeframe spans two distinct living conditions: before and after the implementation of the closed-off management policy. A comparative analysis within this context will assist administrators in reflecting on the policy's impact and making informed decisions. Table 1 presents the raw data (the first five rows) of desensitized student campus card consumption records, providing details such as the student's ID, name, transaction date, transaction time, transaction location, and transaction amount.

Data Preprocessing
Due to formatting inconsistencies, data redundancy and other factors, the raw data extracted from the system cannot be directly used and requires effective structuring and type standardization before subsequent research. Therefore, data preprocessing plays a critical role in facilitating visualization and analysis, and it serves as a crucial step in determining the experimental outcome. We conducted data preprocessing through two primary procedures: data classification and data transformation. These steps ensured that the raw data was appropriately organized and modified, enabling seamless integration into the subsequent research process.

Data Classification
The dataset comprises consumption data from students at the School of Management Science and Engineering, Anhui University of Finance and Economics. It includes transactions from over 80 different locations, such as "Fast Food and Breakfast", "Zhongjing Century Hualian East School North Court", "Spicy Hotpot", "Mixed Food Pancake" and so on. To facilitate analysis and align with students' daily lives, we have categorized consumption scenarios into seven groups: dining, supermarkets, insurance, bathing, electricity, medicine, and others.
It is important to note that the consumption places classified under the "other" category are not mainstream establishments, and they lack a consistent pattern in terms of month or date. This lack of consistency hinders the analysis and overall data visualization. Consequently, these places are not currently included in the analysis.

Discretization of Time Data
To achieve the statistics of variations in daily footfall in cafeteria and the visualization of data in different time periods, it is necessary to discretize the data in the column of "transaction time". The processing method selected in this paper is to use the resample method in Pandas to divide the 24-hour period of a day into 48 segments, with each segment representing a duration of 30 minutes. Consolidating the time data scattered across different segments into a single point holds significant implications for visualizing the daily dining traffic data that follows. Fig. 1 compares the proportion of total consumption amounts in each category. It is evident that dining expenses constituted the predominant portion of consumption expenditure among the students at the School of Management Science and Engineering, representing 76.66%. This percentage surpassed three-quarters of the total, far ahead of the other five categories. Next, supermarket expenses accounted for 8.97% of consumption, mainly consisting of certain necessities required by students during school hours, as well as non-meal food items such as fruit, snacks, and perishable or short-shelf-life products. Finally, insurance and bathing fees, which accounted for a relatively small amount, each comprised only around 5.5%.  Fig. 2 demonstrates the proportion of card swipes among different categories. Although the proportion of dining expenditure was still in the leading position, it is worth noting that the percentage of bathing consumption has expanded to 35.11%. Analyzing the reasons as follows: in actual life scenarios, bathing activities are associated with frequent but low-value credit card transactions. In a student's one-time consumption, multiple or duplicate card swipes often occur due to the student's personal preferences or needs, as well as human errors or equipment malfunctions. Consequently, even though the share of bathing expenses in the total expenditure was not prominent, the number of card swipes associated with "bathing" accounted for over one-third. Besides, the total number of times students spent in supermarkets was 8.75 %, which was about one-sixth of catering consumption. Based on the analysis of Fig. 1 and Fig. 2, it is evident that both in terms of consumption amount and transaction frequency, dining carried the majority of the weight in students' daily life. To enhance students' sense of belonging and provide greater convenience in their academic journey, it is especially vital to explore their dining patterns and understand their eating habits. Subsequently, the construction of canteens can be optimized from multiple perspectives.

Overall Analysis of Canteen Consumption
Before the analysis of the dining rules, items with the corresponding value of "transaction locations" as "dining" needed to be screened out. After processing, the data was reduced from 1.1 million to 630,000.
We continued the analysis of student consumption data in the dining category based on the number of card swipes. Fig.  3 shows the statistics of the average number of transactions per month of students in the past year. From the diagram, we can infer that during the period from April 2022 to May 2022, average number of daily consumptions was about 3000. At this stage, students basically adjusted back from the state of holidays. Following the rhythm of the teaching weeks, undergraduates tended to have a more structured lifestyle. Therefore, the majority of meals, three times a day, were typically taken care of in the students' cafeteria. In June, the value decreased significantly. This phenomenon might be attributed to the prevalence of multiple examinations taking place in the month of June, such as CET4, CET6, the final examination and so on. In order to adapt to the state of preparation and review, students were inclined to adjust their original eating habits. For instance, there was a greater tendency for individuals to opt for ordering takeout, making purchases at supermarkets, and missing the operational hours of the campus cafeteria. From July 2022 to August 2022, the data ushered in a significant reduction. During these two months, the school entered the summer vacation period, leading to the departure of the majority of students, while a few opted to remain on campus during their summer break. For this reason, even if the data at this stage dropped sharply, there were still cafeteria dining records with an average of about 200 times a day.
Besides, September 2022 to December 2022 was the first half of the academic year. Except for December, when there was an abnormality, the number of consumptions in the cafeteria was fairly stable in the other three months, remaining at around 2,500. In December 2022, due to policy factors, a large number of students were being repatriated, and some canteen windows were closed and no longer open. After the middle of the month, basically no students stayed on campus, so the consumption data generated was less than half of usual. At the end of February 2023, students started school, and the data recovered and remained around 2000 in the following two months.

Statistical Analysis of Card Swipe Frequency at
Different Stages In order to explore students' meal patterns further and generalize more specific meal habits, we selected eight consecutive teaching weeks from the three semesters included in the period April 2022 -April 2023, respectively, where students' behaviors were more regular and stable. For comparison convenience, we set W0, W1...W8 as the Saturdays of each week, and the specific data treatment is shown in Table 2. Fig. 4 drawn in this way demonstrates a stronger regularity. From Fig. 4, we can observe that the number of student meals exhibited weekly fluctuations and variations at each stage. Specifically, the consumption frequency at each stage reached its lowest point when plotted on the x-axis as W0, W1…W8. By considering the specific values in conjunction with this information, we can deduce that there existed a significant disparity in the number of meals consumed on weekdays versus weekends. The majority of students opted to dine in the on-campus cafeteria during weekdays primarily due to their busy course schedules, whereas weekends saw a notable decrease in the number of meals consumed on campus. Compared to weekdays, the number of meals in the cafeteria on weekends was reduced by about 30%.
In addition, although the weekly dining rules were basically the same, contrasted with the data of different stages, we can find that the attraction of school canteens to students was gradually weakening over time. Specifically, the students' card-swiping instances in April 2023 decreased by about 1,000 in comparison to the same period last year. The reasons for such a marked contrast might be as follows: in 2022, the school implemented closed management, and students were not allowed to enter and leave the campus without special circumstances. The three meals basically relied on the supply of school canteens, which brought considerable benefits to the canteen. However, in the new semester of 2023, owing to the liberalization of the epidemic policy, the school no longer executed closed management. Under any circumstances, any student could freely enter and leave the campus. In terms of diet, the charm of off-campus restaurants has increased, thus diverting some people from dining on campus. It can be seen that in the absence of closed management constraints in the future, campus cafeterias urgently need to explore new development model, enlarge the existing advantages, and improve the infrastructure construction in terms of hardware and software. This will enable them to attract and retain students, thereby further enhancing their competitiveness in comparison to off-campus dining options.

Transaction Active Time Period Statistics
In the analysis of students' dining situation at different time points, we can clearly see from Fig. 5 that there are four high points in the dining curve during the day, corresponding to the time periods of 7:00am to 8:00am, 9:00am to 10:00am, 11:00am to 12:00am, 5:00pm to 6:00pm. In those time, the issues of canteen queue congestion, overcrowding, subpar dining environment, slow meal preparation speed at some stalls, and a range of other problems would be intensified, which was very detrimental to the dining experience of students and teachers. Furthermore, in addition to the peak times during regular meal hours, there was a noticeable minor peak occurring between 9:00am and 10:00am. Upon investigation, the time period was the morning recess of the school, and the primary sources of human traffic was the students who did not eat breakfast before the first class, as well as a part of the students who have recently risen to grab a meal before attending their second class. However, often at this time, some food stalls in the cafeteria have already stopped serving breakfast, and the stalls that were still open might have issues such as limited menu options and cold food. In view of the unique dining habits of students at this time, further improvement of the cafeteria resources should not only be limited to meeting the needs of the majority, but the demands of minority groups should also be included in the scope of optimization and development.

Move the Cafeteria Window Five Meters Back
According to the survey, some stalls in the South Court cafeteria have the problem that the pick-up point is too far from the meal preparation area. On the one hand, it causes the waste of space resources and potential safety hazards due to the lack of space during the peak flow of people. On the other hand, students are unable to witness the sanitary conditions of the kitchen area and the meal preparation process. Meanwhile, the operation of the cafeteria lacks transparency, which increases the safety risks of eating and is not conducive to the joint participation of customers in the supervision of the cafeteria quality.
The measure of moving the cafeteria service windows five meters backward will expand the reception area of the cafeteria and facilitate the school to set up more tables and chairs. More importantly, this initiative saves more space for teachers and students to queue up and place their orders, thus ensuring the operational efficiency of the cafeteria during peak dining periods. Simultaneously, the new space can also be considered to provide various types of seating, such as high chairs, sofa areas, group dining areas, etc., to meet the preferences and needs of different students. Lastly, when students order and wait for their meals, they can see the raw materials, the production process and the sanitary environment inside the stall from a close distance, which will undoubtedly strengthen the impression of the school cafeteria as a clean and hygienic place and make students feel more at ease with the food in the cafeteria and thus more favorable.

Supply the Dishes in Batches During the Peak Period
During the four peak periods of daily dining, the cafeteria can release a batch of fresh, warm dishes every half hour. In this way, students can alleviate concerns about insufficient, unappetizing or cold meals, even if they are unable to catch the first batch of meals served in the cafeteria or prefer to avoid the peak periods. The aim is to gradually establish a staggered dining pattern, dispersing the influx of individuals during peak hours, and ensuring students have an efficient and expedited dining experience on weekdays, when the number of cardholders is at its peak. This approach helps alleviate the operational strain on the cafeteria during high-demand periods. Also, this humanized service will further increase the loyalty of the dining staff and bring more profit to the canteen.

Improve the Soft Power of Canteen Construction
Faced with the diminishing attractiveness and the massive loss of customers on weekends, school cafeterias need to innovate their business environment and create a cultural label of their own, thus increasing the stickiness between students and the cafeteria. For example, establish private rooms offering specialty dishes at competitive prices, while concurrently arranging diverse activities such as indoor games, group gatherings, music performances and so on. Gradually, when selecting venues for teambuilding activities within student clubs, classes, or organizations, the school cafeteria will be considered the top choice. Instead of expending significant effort in selecting and arranging visits to expensive off-campus restaurants with inconvenient transportation, students prioritize utilizing the school cafeteria as their preferred activity space. In addition, cultural festivals, food creativity festivals, cooking competitions, etc., should be held regularly at regular intervals. In line with this, it is recommended to implement online voting and evaluation systems. Creative dishes should be sold to students, so that they can improve their meals and feel the enjoyment of taste and nutritional satisfaction even on campus.

Conclusion
Based on the consumption data of the campus card of the School of Management Science and Engineering of Anhui University of Finance and Economics, this paper used Pandas and Matplotlib to realize the visualization of the consumption data of the student campus card, including the proportion of the number and amount of consumption in each category, the change statistics of the number of consumption in the canteen, the frequency statistics of students' swiping cards and the regular statistics of the active time points of daily transactions in the canteen. Combined with the unique dining habits of the students in the school, this paper presented comprehensive measures for optimizing and developing the school cafeteria based on three key aspects: enhancing canteen infrastructure, improving food supply, and enhancing soft power.
In the future, with the continuous deepening of information construction in colleges and universities, the proliferation of data generated on campus cards is increasing dramatically. Using big data technology to mine, integrate and manage them will aid schools in acquiring a deeper understanding of student behavior patterns, enabling them to precisely optimize resource allocation. Consequently, it will facilitate the provision of more scientifically tailored and effective services and management for teachers and students alike.