简体   繁体   English

使用 pandas 从.xls 文件中获取非空单元格

[英]Fetch non-empty cells from .xls file using pandas

i am new to python.我是 python 的新手。 i want to fetch the values from the cells & empty cells should be discarded.我想从单元格中获取值并且应该丢弃空单元格。 i want to loop through rows & columns & assign to list我想遍历行和列并分配给列表

import pandas as pd
from pandas import ExcelFile
from pandas import ExcelWriter

df=pd.read_excel('16Junedata_03062020_80163767_action_03062020_80163767_2624_01.xls', sheet_name='Sheet4')
#newdf = df.fillna({'business_day':0,'zone_id':0,'site_id':0,'device_id':0})
#newdf = df.fillna(method="ffill")
z_id= df['zone_id']
d_id= df['device_id']
s_id= df['site_id']
vst= df['visit_start_time']
# print(z_id)
# print(d_id)
# print(s_id)

for a,zone_id in z_id.iteritems():
        for b,site_id in s_id.iteritems():
            print(site_id)

You can get the list of non NaN values using below code, this is only for one column:您可以使用以下代码获取非 NaN 值的列表,这仅适用于一列:

zone_id_updated = []
for item in df.zone_id.iteritems():
    if pd.isna(item[1])==False:
        zone_id_updated.append(item[1])

Similarly can be done for other columns.对其他列也可以这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Pandas DataFrame 中将非空单元格向左移动 - Move non-empty cells to the left in pandas DataFrame 如何使用 Pandas 从 .xls 文件中读取合并的单元格 - How to read merged cells from .xls file using pandas 读取CSV文件列中非空单元格的有效方法 - Efficient way to read non-empty cells in a column in CSV file 在循环中处理许多 csv 文件,并使用 Python 从特定列的非空单元格中提取行 - Process many csv files in a loop and extract rows from non-empty cells of a specific column using Python pandas:从DataFrame中打印所有非空行 - pandas: print all non-empty rows from a DataFrame Pandas csv dataframe:在空列中的所有单元格中输入“Null”,在非空列中的所有空单元格中输入“NA” - Pandas csv dataframe: Input “Null” into all cells in empty colums, input “NA” into all empty cells in non-empty colums 计算熊猫数据框行中的非空单元格,并将计数添加为列 - Count non-empty cells in pandas dataframe rows and add counts as a column 将 Excel 文件读取到 dataframe 并将最后一个非空列值复制到空单元格 - Reading Excel file to dataframe and copying last non-empty column value to empty cells 用非空条件填充 pandas 列 - fill a pandas column with a non-empty condition 如何使用 Pandas 仅从 XLS 文件中获取我需要的单元格 select - How to select only the cells I need from a XLS file with Pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM