What I have got is a CSV file with following structure:
column1 column2 column3 column4(day) column5(month&year) column6(time)
column1 column2 column3 column4(day) column5(month&year) column6(time)
column1 column2 column3 column4(day) column5(month&year) column6(time)
...
The columns of the file do not have names. Now I want to merge column4 and column5 and generate a new version of the CSV file so that I have got the complete date in one cell.
What I have tried is following Python code:
def correctDatetime():
with open("inputfile.csv", "r") as source, open("outputfile.csv", "w") as result:
df = pd.read_csv('C:/ProgrammingProjects/LicMonTest/inputfile.csv', header=0)
for row in source:
df['Datetime'] = df[df.columns[3:]].apply(lambda x: ' '.join(x.dropna().astype(str)), axis=1)
result.write(df)
Unfortunately this only generates an empty CSV file. How could I best approach this issue? Any advice would be helpful. Thanks in advance!