in Education by
Here is the example of my data set from some public transports: data set. Date is from 2018-06-01 to 2018-06-30, Time is operation hours, from 5am to 24(0)am, People is the number of peope in that specific date, time and trip. from_to is the where those people enter and leave (one type of trips), and finally weekday. What I need to do here is to create a time table for each trip, for example if I want to create a table for trip "G1_G2", the code I use now is: for i in [0,1,2,3,4,5,6]: for j in [0,1,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]: df['people'][(df['weekday'] == i)&(df['from_to'] == 'G1_G2') & (df['time'] == j)].mean() Where "i" is weekday, and j is the operating hours. The result will be a table like: output table But the problem here is that each table will take about 10 seconds to create, there are around 11,000 types of trip here, which will take 30 something hours. Is there other ways to do this with higher efficiency using python? Thanks in adanvance! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Probably using groupby and aggregate you can do this. import pandas as pd Deliberately I use here a small data example. If you have many smaller tables as I interpret from your description, you may want to concatenate before. df = pd.DataFrame({'date':['2018-06-01', '2018-06-01', '2018-06-01', '2018-06-02', '2018-06-02', '2018-06-02'], 'time':[0,0,0,1,1,1], 'people':[0,2,2,4,5,7], 'from_to':['BR13_BR13', 'BR13_BR13','BR13_BR13','BR13_BR13','BR13_BR13','BR13_BR13'], 'weekday':[4,4,4,5,5,5]}) The following code results in a long format, not in the wide format that your output table has, but it can be made wide if you wanted: df.groupby(['from_to', 'time', 'weekday']).aggregate('people').mean() Which results in the following output: from_to time weekday BR13_BR13 0 4 1.333333 1 5 5.333333 Name: people, dtype: float64

Related questions

0 votes
    Here is the example of my data set from some public transports: data set. Date is from 2018-06-01 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Which of the following can improve the performance of an AI agent? a) Perceiving b) Learning c) Observing d) All of the mentioned...
asked Jan 15, 2023 in Education by JackTerrance
0 votes
    R comes with a ________ to help you optimize your code and improve its performance. (a) debugger (b) ... Analysis of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have 3 table a,b,c. select * from a select * from b where aid in (select id from a) ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have 3 table a,b,c. select * from a select * from b where aid in (select id from a) ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    I have noticed that when One Hot encoding is used on a particular data set (a matrix) and used as training data ... how does it happen? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Machine Learning refers to. a) Computer systems ability to improve its performance Select the correct answer from above options...
asked Nov 12, 2021 in Education by JackTerrance
0 votes
    __________ is increasingly being used in server systems to improve performance by caching frequently used data, ... in portion Storage and File Structures of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    How can we improve the Performance of an ASP.NET Web Page?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    How to Improve Security Performance?...
asked Oct 24, 2020 in Technology by JackTerrance
0 votes
    i have multiple excel files with uniform column names, except for one. One file calls it EndOfMarchStatus, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    How can I remove emojis that start with '\x' when reading a csv file using pandas in Python? The ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I have a simple method to search a pandas dataframe column for a list of keywords; however, I'd like to create a ... do everyth 28,passei o dia com o meu amor comemo demai...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    Problem: Select first N rows and last row in Python Pandas. only gets 1 row which is index 9 and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    So I have a list of people, each of them are given more than 2 books, 4 books are possible. I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
...