title: How to read a file name and append the name to a new column in a csv file using python pandas?
body: <p>As the question says the requirement, I am using ubuntu os. I need to get the file name which I have in a folder called <strong>Sample_csv_files</strong> each represents a file in the same format except the id, e.g.</p>
  <pre><code>agent_op_023jlafa45459a390-.csv
  agent_op_3rjfigr837yw749jh-.csv
  agent_op_f78jlajk7h6559a39-.csv
  </code></pre>
  <p>Here I need to get those IDs and add them in a new_column. If I take for example the <strong>agent_op_023jlafa45459a390-.csv</strong> file, then I should populate the new_column with the id alone, e.g.</p>
  <pre><code>x  | y | new_column
  abc|xyz| 023jlafa45459a390
  </code></pre>
  <p>for the entire CSV file. Similarly I need to do this for the rest of the files.
  Hope can understand the description above.</p>
  <p>Anyone can help me to solve it out.</p>
  <pre><code>df1 = pd.read_csv('/home/user/Downloads/Sample_csv_files/agent_op_023jlafa45459a390-.csv')
  df1['filename'] = &quot;agent_op_023jlafa45459a390-.csv&quot;
  df1['filename'] = df1['filename'].map(lambda x: x.lstrip('agent-output').rstrip('-.csv'))
  df2 = []
  df3 = df1['filename'].append(df2)
  print(df1.head(10))
  df1.to_csv(&quot;/home/user/Downloads/sample_work.csv&quot;, index=False)
  </code></pre>