Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the questionnaire by python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to realize the questionnaire of python". In the operation of the actual case, many people will encounter such a dilemma. Then 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!

Case review

The traditional mascot is still a cute beautiful girl.

The shopping street wants to design a mascot for publicity.

Distribute questionnaires to shopkeepers and customers in the commercial street

The questions in the questionnaire include a survey on the preference for mascots. There is also a survey of the attractiveness of the shopping street, options include: activities, promotions, a full range of goods and a good service attitude. Question: are there any differences between shopkeepers and customers in their answers to these questions? What kind of operational advice can be obtained from the questionnaire? )

Data import and contingency table

Store the data in csv format and import it into python. And calculate the support of customers and shopkeepers to the charm of the commercial street, and generate contingency tables.

Import pandas as pd

# Import data

Survey = pd.read_csv ('survey.csv', encoding =' utf-8')

# calculate the support of customers and shopkeepers for the charm of the high street

Su1 = pd.DataFrame ({'customer': survey [survey. Position = 'customer']. Answer 6.value_counts ()})

Su2 = pd.DataFrame ({'shopkeeper': survey [survey. Position = 'shopkeeper']. Answer 6.value_counts ()})

# merge data boxes to generate contingency tables

Survey2 = pd.concat ([su1,su2], axis=1)

Survey2

To make the observation more intuitive, draw a stacked bar chart of the contingency table below.

Import matplotlib.pyplot as plt

From pylab import *

Mpl.rcParams ['font.sans-serif'] = [' SimHei']

Survey2.T.plot (kind='bar', stacked=True, color= ['black','gold','red','green'], grid=False)

Plt.show ()

It can be seen intuitively from the picture that shopkeepers pay more attention to whether the goods are complete, and customers are more concerned about the benefits. Shopkeepers put a lot of thought into the activities, but the customers are less interested and pay more attention to the service attitude of the shopkeepers. In addition, 35 customers are satisfied with the service in the commercial street, while only 9 shopkeepers choose a good service attitude, which shows that the shopkeeper lacks confidence in his service attitude to a certain extent.

Although some conclusions can be analyzed from the chart, in order to objectively explain whether there is a significant deviation between the customer and the shopkeeper, it is necessary to carry out an independence test.

Independence test (chi-square test)

Zero assumes that the answers of shopkeepers and customers are independent, that is, there is no significant difference.

The alternative assumes that the answers of the shopkeeper and the customer are affected by their respective positions, that is, they have different opinions.

The probability is not significant (5%) negates the zero hypothesis, that is, whether there is a significant deviation between the customer and the shopkeeper.

The probability equals or exceeds the significance level (5%) and retains the zero assumption, that is, the opinions of customers and shopkeepers are not affected by their respective positions.

From scipy.stats import chi2_contingencychi2_contingency (survey2)

The result is:

(55.488971138570164, 5.3999746517395078e-12, 3, array ([[25.36945813, 24.63054187], [30.44334975, 29.55665025], [22.32512315, 21.67487685], [24.86206897,24.13793103]))

Where the first value represents the chi-square value, the second value represents the pvalue, that is, probability, and the third value represents the degree of freedom. The probability here is almost zero, which is obviously less than 5%. As a result, shopkeepers and customers have different expectations of the high street.

Next, it analyzes whether there is any difference between the customer and the shopkeeper on the choice of mascot.

Su11 = pd.DataFrame ({'customer': survey [survey. Position = 'customer']. Answer 7.value_counts ()})

Su22 = pd.DataFrame ({'shopkeeper': survey [survey. Position = 'shopkeeper']. Answer 7.value_counts ()})

Survey3 = pd.concat ([su11.T,su22.T], axis=0)

Survey3

Obviously, there is a difference of opinion between the customer and the shopkeeper. There are too many customers who did not fill in the answers, and almost all the shopkeepers chose cute girls, and only three people chose the traditional mascot. In the data analysis, there is a frequency of less than 5, so chi-square test should be avoided as far as possible. There are basically the same number of customer answers on both sides, and many people do not fill in the answers, which proves that the customer is not interested in this. Combined with the analysis of answer 6, customers are more looking forward to sales promotion. Therefore, instead of designing mascots, it is better to carry out some discount promotion activities.

A few small concepts

Independence test: a method to analyze whether there is a correlation between the two attributes of a contingency table. First of all, the zero hypothesis is put forward, that is, "the two attributes are independent of each other", that is, they are not related. If the probability is less than 5%, abandon the zero hypothesis and choose the alternative hypothesis, that is, "the two attributes are not independent of each other." If the probability is greater than or equal to 5%, the zero assumption is retained.

This is the end of the questionnaire on how to achieve python. 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report