So, I have this problem in my program. I have a csv file that contains this data:
CSV: 1
- -- 0 100 200 300
06/02/2017 Mon
07/02/2017 Tue
08/02/2017 Wed
and other csv files contain:
CSV: 2
Date Hour Data
07/02/2017 200 0.1
06/02/2017 100 2.1
08/02/2017 300 4.1
What I'm trying to do is put the value of the DATACSV: 2 column in CSV: 1, using DATEand Hourto match it.
Output Example:
CSV: Output
- -- 0 100 200 300
06/02/2017 Mon 2.1
07/02/2017 Tue 0.1
08/02/2017 Wed 4.1
This is my code for Csv: 1
import pandas as pd
df1 = pd.read_csv('sample.csv')
date_df1 = df1["Date"]
day_df1 = df1["Day"]
df2 = pd.DataFrame(columns=['-','--','0000','0100','0200','0300','0400','0500','0600'
,'0700','0800','0900','1000','1100','1200','1300'
,'1400','1500','1600','1700','1800','1900','2000'
,'2100','2200','2300'])
df2["-"] = (date_df1.values)
df2["--"] = (day_df1.values)
df2 = df2.drop_duplicates(['-'], keep='first')
df2 = df2.drop_duplicates(['--'], keep='last')
df2.to_csv('try.csv', header=True, index=False, encoding='utf-8')
But I can not figure out how to insert data.