i have a script that first reads in a table data with pandas, then does some computations:
import numpy as np
import sys
import pandas as pd
originaldata = pd.read_csv('../file.txt', sep='\t', skiprows = 31)
originaldata = originaldata.fillna(0)
.... (rest of the code)
I would like to pass the file name in command line rather than typing it in the code each time there is a different file. is my code right?
import numpy as np
import sys
import pandas as pd
filename = sys.argv[-1]
originaldata = pd.read_csv('filename', sep='\t', skiprows = 31)
originaldata = originaldata.fillna(0)
.... (rest of the code)
so on the command line i would type:
$python program1.py file.txt
update:
so from the comments i learned that one mistake is that the
originaldata = pd.read_csv('filename', sep='\t', skiprows = 31)
should be
originaldata = pd.read_csv(filename, sep='\t', skiprows = 31)
and instead of using sys.argv[-1] , argparse is more useful. so here i changed my code to:
import argparse
parser = argparse.ArgumentParser(description='program1 ')
parser.add_argument('-i','--input', help='Input file name',required=True)
originaldata = pd.read_csv(args.input , sep='\t', skiprows = 31)
note i'm using Anaconda 's Spyder IDLE which contains the pandas module, for my program, it runs well within the IDLE but is having problem with command line. Turns out Anaconda uses pythonwin , so after setting path to pythonwin, on my command line i typed :
$pythonwin program1.py file.txt
then a 'python for Win32' popped up and says 'still can't get my hands on win32ui' . i'm so confused now. does it have anything to do with me using a 64 bit computer?