0

I have 3 days of time series data with multiple columns in it. I have one single DataFrame which includes all 3 days data. I want 3 different DataFrames based on Column name "Dates" i.e df["Dates"]

For Example:

Available Dataframe is: df

enter image description here

Expected Output: Based on Three different Dates

First DataFrame: df_23

enter image description here

Second DataFrame: df_24

enter image description here

Third DataFrame: df_25

enter image description here

I want to use these all three DataFrames separately for analysis.

I tried below code but I am not able to use those three dataframes (Rather I don't know how to use.) Can anybody help me to work my code better. Thank you.

enter image description here

Above code is just printing the DataFrame in three DataFrames that too not as expected as per code!

enter image description here

4

1 Answer 1

1

Unsure if your saving your variable into a csv or keep it in memory for further use,

you could pass each unique value into a dict and access by it's value :

    print(df)
     Cal  Dates
0    85     23
1    75     23
2    74     23
3    97     23
4    54     24
5    10     24
6    77     24
7    95     24
8    58     25
9    53     25
10   44     25
11   94     25



d = {}

for frame, data in df.groupby('Dates'):
    d[f'df{frame}'] = data


print(d['df23'])
    Cal  Dates
0   85     23
1   75     23
2   74     23
3   97     23

edit updated request :

for k,v in d.items():
    i = (v['Cal'].loc[v['Cal'] > 70].count())
    print(f"{v['Dates'].unique()[0]} --> {i} times")
23 --> 4 times
24 --> 2 times
25 --> 1 times
Sign up to request clarification or add additional context in comments.

3 Comments

If I want to iterate through Index values and dictionary (d--> dictionary of df) How can I do that? For Example: If I want to count how many times 'cal' column values are exceeding '70' per day! Expected output from your dataframe should be: on 23 --> 4 Times, on 24--> 2 times and on25--> 1Time
@Analyst updated for you - but this is basic for looping and working with python data types, I suggest you look at some basic tutorials for python and maybe search SO a little :) ask a new question if things get to complex but always post your data as text, show your code and paste any errors.
Yeah Thanks. I will do that from next for sure. I am trying out. I will post my code and error too for reference as well. Thanks for suggestions. Appreciate for that.

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.