If you put code in function which gets path then you can simply run it with different paths
import pandas as pd
# --- functions ---
def my_function(path):
df = pd.read_csv(files, delim_whitespace=True, header=None) # PEP8: arguments witout spaces around `=`
df[len(df.columns)] = 1
df_no_indices = df.to_string(index=False)
print(df_no_indices)
# --- main ---
first_path = "/qdata/projects4/solidground/bsh_o13/import/horizon/raw/Unit_X.Q_085"
my_function(first_path)
my_function('/other/path/to/file')
my_function('/different/path/to/file')
And if you put paths on list then you can use for
-loop
import pandas as pd
# --- functions ---
def my_function(path):
df = pd.read_csv(files, delim_whitespace=True, header=None) # PEP8: arguments witout spaces around `=`
df[len(df.columns)] = 1
df_no_indices = df.to_string(index=False)
print(df_no_indices)
# --- main ---
my_files = [
"/qdata/projects4/solidground/bsh_o13/import/horizon/raw/Unit_X.Q_085",
'/other/path/to/file',
'/different/path/to/file',
]
for path in my_files:
my_function(path)
And later you can use os.listdir()
, os.walk()
or grep.grep()
to create list with files - and use this list with for
-loop.
Some functions may give filename
without directory
and they need
path = os.path.join(directory, filename)
to create full path.