データフレームの各列の合計を出力するプログラムを作成しましたが、数値が連結して出力されてしまいました。
Python
1def hr_serach(another_time,start_day): 2 day_time = datetime.datetime.now() 3 now = day_time.strftime('%Y-%m-%d') 4 start = day_time - datetime.timedelta(days=start_day) 5 start = start.strftime("%Y-%m-%d") 6 conn = sqlite3.connect(DBfile) 7 c = conn.cursor() 8 df = pd.read_sql("select * from harvest where now between '" + str(start) + "'and'"+ str(now) +"'",conn) 9 print(df) 10 df = df[df['now'] == another_time] 11 print(another_time) 12 print(df) 13 white = df["white"].sum() 14 brown = df["brown"].sum() 15 big_white = df["bigwhite"].sum() 16 big_brown = df["bigbrown"].sum() 17 return[white,brown,big_white,big_brown] 18 19another = datetime.datetime(2022,8,31) 20another = another.strftime("%Y-%m-%d") 21test = hr_serach(another,100) 22print(test)
データフレームの中身
now Buli white brown bigwhite bigbrown 0 2022-08-31 1 1 1 2 1 1 2022-08-31 2 3 5 7 12 2 2022-08-31 3 4 5 5 4 3 2022-09-01 1 2 1 1 2
出力結果
now Buli white brown bigwhite bigbrown 0 2022-08-31 1 1 1 2 1 1 2022-08-31 2 3 5 7 12 2 2022-08-31 3 4 5 5 4 3 2022-09-01 1 2 1 1 2 2022-08-31 now Buli white brown bigwhite bigbrown 0 2022-08-31 1 1 1 2 1 1 2022-08-31 2 3 5 7 12 2 2022-08-31 3 4 5 5 4 ['134', '155', '275', '1124']
数値を連結するのではなく、合計値を出力したいです。

回答1件
あなたの回答
tips
プレビュー