我有两个数据帧,我正在for循环中。当我试图附加两个Dataframes时,列名在行之间填充。 我做了一些研究并使用了列表,但我无法让列表对我起作用,这是我的代码
def generatesalesreport3():
if g_month is not None and g_year is not None:
if (g_month == '1: January to March'):
r_month = ['January','February','March']
r_year = int(g_year)
elif(g_month == '2: April to June'):
r_month = ['April', 'May', 'June']
r_year = int(g_year)
elif(g_month == '3: July to Septempber'):
r_month = ['July', 'August', 'September']
r_year = int(g_year)
else:
r_month = ['October', 'November', 'December']
r_year = int(g_year)
ra = list()
rb= list()
for qmonth in r_month:
monnum = month_dict[qmonth]
resultb1 = df_b1.loc[(df_b1['month'] == monnum) & (df_b1['year'] == r_year)]
resultb2 = df_b2.loc[(df_b2['month'] == monnum) & (df_b2['year'] == r_year)]
resultb1 = resultb1.append(resultb2)
print(resultb1)
Image to the result of above code please check
所以,我的要求是,我不想让那些列名出现在结果中,然后我把完整的数据帧放到一个数据帧中,我必须基于模型列进行一些操作
只需从“resultb2”数据框中筛选出列,然后追加。比如:
相关问题 更多 >
编程相关推荐