python if条件判断dataframe是否为空

python if条件判断dataframe是否为空,第1张

python if条件判断dataframe是否为空
在使用python for循环做数据处理时,会遇到某些文件为空,导致程序报错,可以使用dataframe.empty加if条件判断进行解决

例如:

1 data = pd.read_csv(file, skiprows=1, header=None, error_bad_lines=False)
2 if data.empty:
3     pass
4 else:
5     do

或者

1 data = pd.read_csv(file, skiprows=1, header=None, error_bad_lines=False)
2 if not data.empty:
3     do

timestamp转字符串,直接str(tmp)转换即可

statistics_date_list_tmp = result['report_time'].tolist()
statistics_date_list = [str(tmp).split()[0] for tmp in statistics_date_list_tmp]

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/791291.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-05
下一篇2022-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存