Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how to get the name of the next month, given the name of the current month:</p> <pre><code>import calendar nextmonth = calendar.month_name[1:][(calendar.month_name[1:].index(month) + 1) % 12] </code></pre> <p>And here's that same logic applied to your script, with a few other improvements :) Run this script as "<code>./myscript.py somemonth someyear</code>". It'll output a CSV file named <code>nextmonth year MRG.csv</code>, even taking into account localization and wrapping the year properly.</p> <pre><code>import pandas as pd import calendar import sys if len(sys.argv) != 3: print "Usage: {0} &lt;month&gt; &lt;year&gt;".format(sys.argv[0]) month, year = sys.argv[1:] if not month in calendar.month_name: print "Invalid month! Month must be one of:{0}".format(str(calendar.month_name)) if not year.isdigit(): print "Invalid year! Year must be a number." nextmonth = calendar.month_name[1:][(calendar.month_name[1:].index(month) + 1) % 12] df1 = pd.read_csv("data csv 1\{0} {1} 1 UUedit1.csv".format(month, year), delimiter = ",") df2 = pd.read_csv("data csv 1\{0} {1} 2 UUedit2.csv".format(month, year), delimiter = ",") merged = df1.merge(df2, on="Unique Element") delcols = "Element_y", "number_y", "date_y", "title_y", "name_y" for delcol in delcols: del merged[delcol] merged.rename(columns={"name_x": "name", "rdate_x": "date", "title_x": "title", "number_x": "number", "Element_x": "Element"}, inplace = True) merged = merged.sort("Element").reset_index(drop=True) merged = merged.sort("date").reset_index(drop=True) if month == calendar.month_name[-1]: year = str(int(year + 1)) merged.to_csv("{0} {1} MRG.csv".format(nextmonth, year), index=False, sep = ",") </code></pre> <p>If you don't need the next-month feature (sounds like you actually don't), take out these two lines:</p> <pre><code>nextmonth = calendar.month_name[1:][(calendar.month_name[1:].index(month) + 1) % 12] [...] if month == calendar.month_name[-1]: year = str(int(year + 1)) </code></pre> <p>and replace the last line with:</p> <pre><code>merged.to_csv("{0} {1} MRG.csv".format(month, year), index=False, sep = ",") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload