首页 > 编程语言 >python pandas DataFrame, Series 为空的情况

python pandas DataFrame, Series 为空的情况

时间:2023-03-10 10:56:15浏览次数:28  
标签:empty2 python Series DataFrame df print empty ser

 

 

#!/usr/bin/evn python

import numpy as np
import pandas as pd



df_empty = pd.DataFrame({"empty_index":[]})
print("df_empty:",df_empty)

if df_empty.empty:
    print("df_empty is empty")  # df_empty is empty
else:
    print("df_empty is not empty")

ser_empty = pd.Series({"empty_index":[]})
print("ser_empty:",ser_empty)

if ser_empty.empty:
    print("ser_empty is empty")
else:
    print("ser_empty is not empty") # ser_empty is not empty

ser_empty2 = pd.Series()
print("ser_empty2:",ser_empty2)
if ser_empty2.empty:
    print("ser_empty2 is empty") # ser_empty2 is empty
else:
    print("ser_empty2 is not empty")
E:\remote_project\lianghua2023\monitor\venv\Scripts\python.exe E:/remote_project/lianghua2023/monitor/app/henry/helloC.py
E:/remote_project/lianghua2023/monitor/app/henry/helloC.py:23: DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
  ser_empty2 = pd.Series()
df_empty: Empty DataFrame
Columns: [empty_index]
Index: []
df_empty is empty
ser_empty: empty_index    []
dtype: object
ser_empty is not empty
ser_empty2: Series([], dtype: float64)
ser_empty2 is empty

Process finished with exit code 0

 

标签:empty2,python,Series,DataFrame,df,print,empty,ser
From: https://www.cnblogs.com/music-liang/p/17202612.html

相关文章

  • 只需几步小白也能写出python爬虫代码
    关于爬虫怎么写,我们应该从最简单的商品的批量爬取说起,下面就是我写的一个简单的Python代码,看如何爬取并并存储到MySQL数据库中。首先,需要安装必要的第三方库,如:requests,Bea......
  • python工具jupyternotebook页面打开空白问题解决方法
    jupyternotebook页面打开空白问题解决方法下载anaconda自带的jupyternotebook找到这个配置文件C:\Users\Administrator.jupyter\jupyter_notebook_config.py打开找......
  • python os模块使用(遍历指定目录)
    pythonos模块使用(文件遍历)需求如下遍历指定目录,完成以下操作1:判断该目录下所有的文件的名称及大小,文件大小以用户选择的方式显示(KB,MB,B)list_file()oslistdirfile......
  • Python基础【16】import module的4种方式
    1.importas::先将module导入,再重新命名,然后调用module里面的方法.importmodule1asmod2.from import::直接把module的内部函数导入当前的module:from module1 ......
  • python读写excel文件调研
    xlrd、xlwt和openpyxl模块的比较:1)xlrd:对xls、xlsx、xlsm文件进行读操作–读操作效率较高,推荐2)xlwt:对xls文件进行写操作–写操作效率较高,但是不能执行xlsx文件3)ope......
  • python环境安装
    安装python1、python下载链接:https://www.python.org/downloads/windows/2、安装python 傻瓜式安装请注意,一定要勾选 AddPython3.8toPATH,这样可以将Python命令......
  • Python 爬虫之 xpath
    0x01XML基础xpath是在XML文档中搜索内容的一门语言HTML是XML的一个子集XML代码举例:<book><isbn>978xxxxxxxx</isbn><name>XML从入门到精通</name......
  • 安装python3 for Centos
     以安装3.7.5为例下载安装包wgethttp://npm.taobao.org/mirrors/python/3.7.5/Python-3.7.5.tar.xz 解压xz-dPython-3.7.5.tar.xztar-xfPython-3.7.5.tar......
  • python中的时间处理
    python程序编写中的时间处理涉及三种:1、时间的显示;2、时间的转换;3、时间的运算。时间处理模块:time模块时间的三种表示方式:①时间戳,从1970年1月1日开始,每过1s增加1,如......
  • 实验1 Python开发环境使用和编程初体验
    #实验任务1#1.1.py#用法1print('hey,u')#用法2print('hey','u')x,y,z=1,2,3print(x,y,z)#用法3print('x=%d,y=%d,z=%d'%(x,y,z))print('x={},y={},z={}'.for......