import pandas as pd
pd.set_option('display.unicode.east_asian_width', True)
series = pd.Series(
['1/1', '1/2', '1/3', '1/4', '1/5', '1/6', '1/7', '1/8', '1/9', '1/10'],
name = 'Date')
df1 = pd.DataFrame({
'Date': ['1/1', '1/2', '1/3', '1/4', '1/5', '1/6', '1/7',
Weather: ['Clear', 'Clear', 'Cloudy', 'Clear', 'Clear', 'Clear', 'Clear', 'Clear', 'Clear',
})
dfx=pd.merge(series, df1, on='date', how='left')
# dfx = df1.set_index('date') .reindex(series).reset_index()
print(dfx)
#
date weather
01/1 Clear
1/2. Clear
2 1/3 Cloudy
3 1/4 sunny
41/5 Cloudy
51/6 Cloudy
6 1/7 Clear
7 1/8 NaN
81/9 NaN
91/10 NaN
© 2024 OneMinuteCode. All rights reserved.