If your data frame is defined and prefilled, you can create a new column and fill it as follows
If you want to incorporate data from all excel files into one data frame, your algorithm might be the following:
df['Date'] = 'desired value'
. This automatically creates Date
column in the data frame and fills it with desired value
. If you want to incorporate data from all excel files into one data frame, your algorithm might be the following:
- Define an empty list, e.g., named
acc
(it will be used later).
- Use
os.path.walk
(os.walk
in Py3) orglob.glob
to iterate over all files;
- Load data from each file using pandas, e.g.
pandas.read_csv
,pandas.read_excel
;
- Once you iterating files, you know their names; Let
filename
is the current filename of a file being loaded intodf
; You can just dodf['Dates'] = filename
;
- Append each df to
acc
list;
- Use
pd.concat
to combine all dfs stored inacc
into a new data frame.