Sunday, 19 November 2023

Adding new column in dataframe after geting the info from filename in python

 import os

import pandas as pd

source_folder = r"D:\\DATA"

dest_folder = r"D:\\pdata"


for file in os.listdir(source_folder):

    if file.startswith("ABC")  and file.endswith(".csv"):

        r=file.rfind("_")

        h=file[r:][9:15]

        data= pd.read_csv("D:\\DATA\\"+file+" ")

        data['Time']= h

        data.to_csv("D:\\pdata\\updated_"+file)

No comments:

Post a Comment