I am trying to concatenate some dataframes but I getting the wrong order of columns after done.
My code is:
def numOfDays(date1, date2):
return (date2-date1).days
first_case_report = datetime.strptime('22-01-2020', '%d-%m-%Y')
NumOfdays_reported = numOfDays(first_case_report, datetime.today())
column_names = ['Province/State','Country/Region','Last Update','Confirmed','Deaths','Recovered']
df = pd.DataFrame(columns = column_names)
df.to_csv(index=True)
df.head()
Output:
Province/State Country/Region Last Update Confirmed Deaths Recovered
ind = 0
while ind < NumOfdays_reported:
date_report = (pd.Timestamp(first_case_report) + pd.DateOffset(days=ind)).strftime('%m-%d-%Y')
url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/{0}.csv".format(date_report)
source = pd.read_csv(url,index_col=0,parse_dates=[0])
df = pd.concat([df,source], sort=True)
ind += 1
df.head()
Output:
Confirmed Country/Region Deaths Last Update Latitude Longitude Province/State Recovered
The last df.head() shows that the columns are messed up, for example compare the column Province/State with the df.head() executed, why is that happening?
Any ideas would be highly appreciated.
Thanks a lot beforehand.