Python Forum
How to include input as part of variable name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to include input as part of variable name
#3
periods = {10:None, 50:None, 100:None}

for period in periods:
    new_df = df.copy()
    new_df[f'{period}_MA'] = df_name['Adj Close'].rolling(window=period).mean() 
    periods[period] = new_df
    print(f'First five lines of period {period} are:')
    print(new_df.head(), '\n')
Reply


Messages In This Thread
RE: How to include input as part of variable name - by deanhystad - Sep-14-2021, 02:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to include one script into another? MorningWave 8 607 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  Calling functions by making part of their name with variable crouzilles 4 907 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  how include a python code in notpad++ plugin akbarza 2 695 Sep-25-2023, 08:25 PM
Last Post: deanhystad
  Regex Include and Exclude patterns in Same Expression starzar 2 864 May-23-2023, 09:12 AM
Last Post: Gribouillis
  input variable choice MCL169 7 1,253 Feb-19-2023, 09:00 PM
Last Post: MCL169
  Need help on how to include single quotes on data of variable string hani_hms 5 2,183 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  How to write a part of powershell command as a variable? ilknurg 2 1,169 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,383 May-07-2021, 12:39 AM
Last Post: MDRI
  Can I include text using artist? tetrisbot 0 1,462 Aug-13-2020, 08:13 PM
Last Post: tetrisbot
  trying to input a variable using random.choice python63 9 3,733 Aug-13-2020, 05:37 PM
Last Post: python63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020