[Solved] Forecasting basis the historical figures

You need to join those two dataframes to perform multiplication of two columns. merged_df = segmentallocation.merge(second,on=[‘year’,’month’],how=’left’,suffixes=[”,’_second’]) for c in interested_columns: merged_df[‘allocation’+str(c)] = merged_df[‘%of allocation’+str(c)] * merged_df[c] merged_df year month segment x y z k %of allocationx %of allocationy %of allocationz %of allocationk x_second y_second z_second k_second allocationx allocationy allocationz allocationk 0 2018 FEB A 2094663 … Read more

[Solved] What is a DEF function for Python [closed]

def isn’t a function, it defines a function, and is one of the basic keywords in Python. For example: def square(number): return number * number print square(3) Will display: 9 In the above code we can break it down as: def – Tells python we are declaring a function square – The name of our … Read more

[Solved] How to execute event repeatedly in Python?

Here’s a simple example using a timer. The screen is filled with a color that changes every 0.4 seconds. import pygame import itertools CUSTOM_TIMER_EVENT = pygame.USEREVENT + 1 my_colors = [“red”, “orange”, “yellow”, “green”, “blue”, “purple”] # create an iterator that will repeat these colours forever color_cycler = itertools.cycle([pygame.color.Color(c) for c in my_colors]) pygame.init() pygame.font.init() … Read more

[Solved] Matplotlib spacing in xaxis

Is this what you want?, try adding the below lines of code to your code: plt.xticks(rotation=90) plt.gca().margins(x=0) plt.gcf().canvas.draw() tl = plt.gca().get_xticklabels() maxsize = max([t.get_window_extent().width for t in tl]) m = 0.2 # inch margin s = maxsize/plt.gcf().dpi*150+2*m margin = m/plt.gcf().get_size_inches()[0] plt.gcf().subplots_adjust(left=margin, right=1.-margin) plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1]) 4 solved Matplotlib spacing in xaxis

[Solved] Scraping web pages with Python vs PHP? [closed]

In my opinion, I would go with python, because of its excellent string handling capabilities compared to PHP. Also there are a lot of cool libraries that python has , that make Scraping web pages a bliss. Some libraries you should check out are : Beautiful soup Scrappy I have personally used BeautifulSoup and its … Read more

[Solved] How to allow caps in this input box program for pygame?

If you change the corresponding code to: elif inkey <= 127: if pygame.key.get_mods() & KMOD_SHIFT or pygame.key.get_mods() & KMOD_CAPS: # if shift is pressed or caps is on current_string.append(chr(inkey).upper()) # make string uppercase else: current_string.append(chr(inkey)) # else input is lower That should work. If you want more info on keyboard modifier states look here 1 … Read more

[Solved] Replace [1-2] in to 1 in Python

You could use a regex like: ^(.*)\[([0-9]+).*?\](.*)$ and replace it with: $1$2$3 Here’s what the regex does: ^ matches the beginning of the string(.*) matches any character any amount of times, and is also the first capture group\[ matches the character [ literally([0-9]+) matches any number 1 or more times, and is also the second … Read more