【发布时间】:2022-10-20 05:29:07
【问题描述】:
我想要的是我有一个数据框(click_df2):-
date L120_active_cohort_logins L120_active_cohort percentage_L120_active_cohort_logins
0 2022-09-03 45000 199000 22.621906
1 2022-09-04 40000 200000 19.092138
现在基于这个 DataFrame 我想根据 DataFrame 中给出的日期更改所有列的值
这就是我创建 clickhouse 表的方式:-
query = '''CREATE TABLE IF NOT EXISTS repeat_day_by_last_120_active_cohort_v1
(
date Date,
L120_active_cohort_logins Int,
L120_active_cohort Int,
percentage_L120_active_cohort_logins Float
) ENGINE = MergeTree()
ORDER BY date'''
代码如下这是我想要做的: -
click_df2 = pd.read_csv(f'{location}/csv_files/main_data.csv',header=0)
click_df2['date'] = pd.to_datetime(click_df2['date'],dayfirst=True)
client.execute(f'''ALTER TABLE repeat_day_by_last_120_active_cohort_v1 \
UPDATE 'L120_active_cohort_logins' = "{click_df2["L120_active_cohort_logins"]}", \
'L120_active_cohort' = "{click_df2["L120_active_cohort"]}", \
'percentage_L120_active_cohort_logins' = "{click_df2["percentage_L120_active_cohort_logins"]}" \
WHERE 'date' = "{click_df2["date"]}"''')
clickhouse 表中存在的数据 repeat_day_by_last_120_active_cohort_v1 :-
date L120_active_cohort_logins L120_active_cohort percentage_L120_active_cohort_logins
0 2022-09-01 32679 195345 16.728865
1 2022-09-02 32938 196457 16.766010
2 2022-09-03 40746 197586 20.621906
3 2022-09-04 33979 198799 17.092138
更改表 repeat_day_by_last_120_active_cohort_v1 数据后应为:-
date L120_active_cohort_logins L120_active_cohort percentage_L120_active_cohort_logins
0 2022-09-01 32679 195345 16.728865
1 2022-09-02 32938 196457 16.766010
2 2022-09-03 45000 199000 22.621906
3 2022-09-04 40000 200000 19.092138
【问题讨论】:
标签: python pandas dataframe csv clickhouse