Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:31:13+00:00 2026-06-05T11:31:13+00:00

I am working on python ( pandas specifically) to analyze a dataset. (Python is

  • 0

I am working on python (pandas specifically) to analyze a dataset. (Python is too awesome, the power of open source is amazing). I am having trouble with a specific part of my dataset.

I have the following data set,

time,contract,ticker,expiry,strike,quote,price,volume
08:01:08,C,PXA,20100101,4000,A,57.8,60
08:01:11,C,PXA,20100101,4000,A,58.4,60
08:01:12,C,PXA,20100101,4000,A,58,60
08:01:16,C,PXA,20100101,4000,A,58.4,60
08:01:16,C,PXA,20100101,4000,A,58,60
08:01:21,C,PXA,20100101,4000,A,58.4,60
08:01:21,C,PXA,20100101,4000,A,58,60

and it goes on …

I am using pandas to load the data. After this, I would like to be able to do the following, take a volume weighted average of the time there are duplicates.

i.e. since there are two asks at time 08:01:16, I would like to calculate the average price based on volume which would be (58.4*60 + 58*60)/(60+60) and an average of the volume on the volume column which would be (60+60)/2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:31:14+00:00Added an answer on June 5, 2026 at 11:31 am
    In [28]: a = pd.read_csv('aa.csv')
    
    In [29]: a
    Out[29]: 
           time contract ticker    expiry  strike quote  price  volume
    0  08:01:08        C    PXA  20100101    4000     A   57.8      60
    1  08:01:11        C    PXA  20100101    4000     A   58.4      60
    2  08:01:12        C    PXA  20100101    4000     A   58.0      60
    3  08:01:16        C    PXA  20100101    4000     A   58.4      60
    4  08:01:16        C    PXA  20100101    4000     A   58.0      60
    5  08:01:21        C    PXA  20100101    4000     A   58.4      60
    6  08:01:21        C    PXA  20100101    4000     A   58.0      60
    
    In [30]: pd.DataFrame([{'time': k,
                            'price': (v.price * v.volume).sum() / v.volume.sum(),
                            'volume': v.volume.mean()}
                           for k,v in a.groupby(['time'])],
                          columns=['time', 'price', 'volume'])
    Out[30]: 
           time  price  volume
    0  08:01:08   57.8      60
    1  08:01:11   58.4      60
    2  08:01:12   58.0      60
    3  08:01:16   58.2      60
    4  08:01:21   58.2      60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in python I want to extract a dataset with the following structure: Each
Working with Python 2.6 and receiving an annoying error, and I'm still unsure why.
Working with Python in Emacs if I want to add a try/except to a
I'm working in Python for the first time and I've used Mechanize to search
I'm working on python 3.2.2. Breaking my head more than 3 hours to sort
I'm working in python 2.6 and I would like to take gpmetisfile.txt.part.4 and return
I've been working with python for quite a bit of time and I'm confused
I am currently working with Python and have been confused over the fact that
now I am working with python. So one question about dict .... suppose I
I am working in python on appengine. I am trying to create what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.