正在研究一个项目,该项目使用从Davinci Resolve导出的CSV元数据集创建pdf报告。
该程序运行并生成报告,但缺少一些列,我无法弄清楚发生了什么。我已经将usecols属性与想要的列一起传递了,但是仍然遗漏了一些。
我认为这可能与数据类型未正确加载到数据帧中有关,但是我已经尝试过了,但是它不起作用。
我希望PDF报告按示例代码中usecols部分中指定的顺序包含列。 示例csv:
https://www.dropbox.com/s/jsup7f5qrfnqc7e/A003.csv?dl=0
项目使用pandas,jinja2和weasyprint
print(sourcefile, outfile)
df = pd.read_csv(sourcefile,
encoding="utf-16",
usecols=['File Name', 'Camera #', 'Resolution', 'Duration TC', 'Video Codec', 'Camera FPS', 'Comments'],
dtype={"File Name": str,
"Camera #": str,
"Resolution": str,
"Duration TC": str,
"Video Codec": str,
"Camera FPS": float,
"Comments": str,
'Date Modified': str,
'Date Recorded': str
},
na_values=['.', '??', ' '] # Take any '.' or '??' values as NA
)
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("report_template.html")
template_vars = {"title": title,
"data": df.to_html(),
"date": self.date,
}
html_output = template.render(template_vars)
HTML(string=html_output).write_pdf(outfile)
df.head()输出以下内容:
File Name Duration TC Resolution Video Codec Comments Camera # Camera FPS
0 A003C001_191024_R48G.mov 00:01:21:08 3200 x 1800 Apple ProRes 4444 PASS A 50000.0
1 A003C002_191024_R48G.mov 00:01:04:20 3200 x 1800 Apple ProRes 4444 PASS A 50000.0
2 A003C003_191024_R48G.mov 00:01:16:14 3200 x 1800 Apple ProRes 4444 PASS A 50000.0
3 A003C004_191024_R48G.mov 00:01:16:08 3200 x 1800 Apple ProRes 4444 PASS A 50000.0
4 A003C005_191024_R48G.mov 00:02:30:04 3200 x 1800 Apple ProRes 4444 PASS A 50000.0
下面的输出示例:
答案 0 :(得分:0)
这不是一个完整的答案。该答案是为了解决请求,以便从对OP的问题的评论中更详细地显示列重新排序。
File Name,Duration TC,Resolution,Video Codec,Comments,Camera #,Camera FPS
A003C001_191024_R48G.mov,00:01:21:08,3200 x 1800,Apple ProRes 4444,PASS,A,50000.0
A003C002_191024_R48G.mov,00:01:04:20,3200 x 1800,Apple ProRes 4444,PASS,A,50000.0
A003C003_191024_R48G.mov,00:01:16:14,3200 x 1800,Apple ProRes 4444,PASS,A,50000.0
A003C004_191024_R48G.mov,00:01:16:08,3200 x 1800,Apple ProRes 4444,PASS,A,50000.0
A003C005_191024_R48G.mov,00:02:30:04,3200 x 1800,Apple ProRes 4444,PASS,A,50000.0
此示例代码显示了如何根据用户要求使用过滤技术对DataFrame列进行重新排序。
import pandas as pd
# Define column order.
col_order = ['File Name', 'Camera #', 'Resolution', 'Duration TC',
'Video Codec', 'Camera FPS', 'Comments']
# Read CSV file.
df = pd.read_csv('./cameradata.csv')
# Use column name filter to re-order columns.
df = df[col_order]
# Show results.
print(df)
File Name Camera # Resolution Duration TC \
0 A003C001_191024_R48G.mov A 3200 x 1800 00:01:21:08
1 A003C002_191024_R48G.mov A 3200 x 1800 00:01:04:20
2 A003C003_191024_R48G.mov A 3200 x 1800 00:01:16:14
3 A003C004_191024_R48G.mov A 3200 x 1800 00:01:16:08
4 A003C005_191024_R48G.mov A 3200 x 1800 00:02:30:04
Video Codec Camera FPS Comments
0 Apple ProRes 4444 50000.0 PASS
1 Apple ProRes 4444 50000.0 PASS
2 Apple ProRes 4444 50000.0 PASS
3 Apple ProRes 4444 50000.0 PASS
4 Apple ProRes 4444 50000.0 PASS