0

I have a list data like bellow which has 6 things in each element in list

"timestamp , open , high , low , close, volume"
['1606470300000,244.25,244.25,244.00,244.00,489269', 
 '1606470360000,244.05,244.30,244.00,244.15,452854', 
 '1606470420000,244.15,244.20,244.00,244.10,403043', 
 '1606470480000,244.15,244.15,243.95,244.00,370182', 
 '1606470540000,244.05,244.20,244.00,244.15,445286', 
 '1606470600000,244.15,244.25,244.05,244.20,473342', 
 '1606470660000,244.25,244.35,244.00,244.05,491117', 
 '1606470720000,244.05,244.20,244.00,244.20,298261', 
 '1606470780000,244.20,244.25,244.10,244.25,344172', 
 '1606470840000,244.20,244.35,244.20,244.30,347080', 
 '1606470900000,244.30,244.40,244.25,244.30,447630', 
 '1606470960000,244.30,244.30,244.00,244.00,360666', 
 '1606471020000,244.05,244.15,243.95,243.95,467724',
 '1606471080000,243.95,244.10,243.70,244.00,386080', 
 '1606471140000,244.00,244.20,243.70,244.20,166559']

this is a 1 minute data and I want to convert it in 15 minute data

please help

5
  • Pandas Interpolate should do. Commented Nov 29, 2020 at 14:08
  • could you please help me with this Commented Nov 29, 2020 at 14:11
  • your question is uunclear. do u want to regroup ur data by 15mins ? if so read about dataframe.resample Commented Nov 29, 2020 at 14:11
  • yes @ombk want to regroup data by 15mins and I know doing this from csv file but dont know how to do it from list of data . could you please help me Commented Nov 29, 2020 at 14:14
  • 1
    you better work to let us help (not do for) you... so please add what you've been trying so far and explain what 15 minutes mean al all? this question is unclear.. Commented Nov 29, 2020 at 14:27

1 Answer 1

1

Here is one way to do it using pandas.

import pandas as pd
list_data = ['1606470300000,244.25,244.25,244.00,244.00,489269',
 '1606470360000,244.05,244.30,244.00,244.15,452854',
 '1606470420000,244.15,244.20,244.00,244.10,403043',
 '1606470480000,244.15,244.15,243.95,244.00,370182',
 '1606470540000,244.05,244.20,244.00,244.15,445286',
 '1606470600000,244.15,244.25,244.05,244.20,473342',
 '1606470660000,244.25,244.35,244.00,244.05,491117',
 '1606470720000,244.05,244.20,244.00,244.20,298261',
 '1606470780000,244.20,244.25,244.10,244.25,344172',
 '1606470840000,244.20,244.35,244.20,244.30,347080',
 '1606470900000,244.30,244.40,244.25,244.30,447630',
 '1606470960000,244.30,244.30,244.00,244.00,360666',
 '1606471020000,244.05,244.15,243.95,243.95,467724',
 '1606471080000,243.95,244.10,243.70,244.00,386080',
 '1606471140000,244.00,244.20,243.70,244.20,166559']

# Convert to usable a dataframe  
df = pd.DataFrame(list_data)\
         .loc[:, 0]\
         .str.rsplit(",", expand=True)
df.columns = ["timestamp" , "open" , "high" , "low" , "close", "volume"]
df.loc[:, "timestamp"] = pd.to_datetime(df.timestamp.astype(int)*1e6)
df = df.set_index("timestamp")
df = df.astype(float)

# That is how it looks like
df.head()
                       open    high     low   close    volume
timestamp                                                    
2020-11-27 09:45:00  244.25  244.25  244.00  244.00  489269.0
2020-11-27 09:46:00  244.05  244.30  244.00  244.15  452854.0
2020-11-27 09:47:00  244.15  244.20  244.00  244.10  403043.0
2020-11-27 09:48:00  244.15  244.15  243.95  244.00  370182.0
2020-11-27 09:49:00  244.05  244.20  244.00  244.15  445286.0


# resample to 15 min data
df.resample("15min").mean()
Sign up to request clarification or add additional context in comments.

5 Comments

excellent job. I was too lazy to write it all tbh
thank you so much @Alex everything is fine but its giving error OverflowError: Python int too large to convert to C long could you please help
ok thank you all guys and specialy @Alex for your answer error was solved with changing int to 'int64' thank you again
thank you @Alex one more thing this time stamp starts from 15.15 and ends on 15.29 but in this solution it is in different could you tell me reason or solution for that
@AmitSharma There was a mistake in the answer. It is not resample("15m") (which would mean 15 months) but resample("15min").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.