我正在做的是用熊猫生成一个DataFrame:
df_output = pd.DataFrame(columns={"id","Payout date", "Amount"}
“付款日期”列中为日期时间,“金额”列中为浮点数。我正在从csv中获取每一行的值:
df=pd.read_csv("file.csv", encoding = "ISO-8859-1", low_memory=False)
但是当我分配值时:
df_output.loc[df_output['id'] == index, 'Payout date'].iloc[0]=(parsed_date)
pay=payments.get()
ref=refunds.get()
df_output.loc[df_output['id'] == index, 'Amount'].iloc[0]=(pay+ref-for_next_day)
,我将其打印在“付款日期”和“金额”列中,即使正确地将其打印为id,使用NaT表示付款,使用NaN表示金额,即使将其强制转换为浮点数,或使用
df_output['Amount']=pd.to_numeric(df_output['Amount'])
df_output['Payout date'] = pd.to_datetime(df_output['Payout date'])
我也曾尝试过将值传递给DataFrame之前强制转换值,但是没有运气,所以我得到的是:
id Payout date Amount
1 NaT NaN
2 NaT NaN
3 NaT NaN
4 NaT NaN
5 NaT NaN
相反,我正在寻找这样的东西:
id Payout date Amount
1 2019-03-11 3.2
2 2019-03-11 3.2
3 2019-03-11 3.2
4 2019-03-11 3.2
5 2019-03-11 3.2
编辑
print(df_output.head(5))
print(df.head(5))
id Payout date Amount
1 NaT NaN
2 NaT NaN
3 NaT NaN
4 NaT NaN
5 NaT NaN
id Created (UTC) Type Currency Amount Fee Net
1 2016-07-27 13:28:00 charge mxn 672.0 31.54 640.46
2 2016-07-27 15:21:00 charge mxn 146.0 9.58 136.42
3 2016-07-27 16:18:00 charge mxn 200.0 11.83 188.17
4 2016-07-27 17:18:00 charge mxn 146.0 9.58 136.42
5 2016-07-27 18:11:00 charge mxn 286.0 15.43 270.57