如何分解python代码行并过滤掉数据?
我下面有一行代码,我只想过滤掉带有数值的代码,跳过None/Null代码。我该怎么做? 提前谢谢 values=[cell['Value']表示数据中的单元格。values()]如何分解python代码行并过滤掉数据?,python,filter,Python,Filter,我下面有一行代码,我只想过滤掉带有数值的代码,跳过None/Null代码。我该怎么做? 提前谢谢 values=[cell['Value']表示数据中的单元格。values()] import configparser from TM1py.Services import TM1Service config = configparser.ConfigParser() config.read(r'..\config.ini') with TM1Service(**config['tm1ser
import configparser
from TM1py.Services import TM1Service
config = configparser.ConfigParser()
config.read(r'..\config.ini')
with TM1Service(**config['tm1server01']) as tm1source:
with TM1Service(**config['tm1server02']) as tm1target:
mdx1 = """
SELECT non empty {Descendants([plan_version].[plan_version].members,100,LEAVES)} *
{[plan_business_unit].[plan_business_unit].[10120]} *
{[plan_department].[plan_department].[415] } *
{[plan_chart_of_accounts].[plan_chart_of_accounts].[64055] } *
{[plan_exchange_rates].[plan_exchange_rates].[local] } *
{[plan_lines].[plan_lines].[line 1] }
on 0,
{[plan_time].[plan_time].[Dec-2004]} on 1
FROM [plan_BudgetPlanLineItem]
"""
mdx2 = """
SELECT non empty {[plan_version].[plan_version].[FY 2004 Budget]} *
{Descendants([plan_business_unit].[plan_business_unit].members,100,LEAVES)} *
{Descendants([plan_department].[plan_department].members,100,LEAVES) } *
{Descendants([plan_chart_of_accounts].
[plan_chart_of_accounts].members,100,LEAVES) } *
{[plan_exchange_rates].[plan_exchange_rates].[local] } *
{Descendants([plan_lines].[plan_lines].members,100,LEAVES) }
on 0,
{[plan_time].[plan_time].[Dec-2004]} on 1
FROM [plan_BudgetPlanLineItem]
"""
data = tm1source.data.execute_mdx(mdx1, cell_properties=['Value'])
values = [cell['Value'] for cell in data.values()]
tm1target.data.write_values_through_cellset(mdx1, values)
# this for loop returns 1 row when MDX1 is used and that data does move to
# the target server. Using MDX2 returns 13 rows but the values listed do not appear
# in the target server
for x in data.values():
print(x['Value'])
如果单元是数据帧:
values = cell['values'].notnull().tolist()
是,您只能过滤列表中的数值:
values = [
cell['Value']
for cell in data.values()
if isinstance(cell['Value'], (int, float))
]
请提供您当前工作的输入和输出,以便更好地理解。添加了完整的代码。感谢您的快速回复。我们是否能够将此代码扩展/分解为多行?这个语句叫做python lambda还是列表理解?我是pythonmy的新手我的回答是在你添加代码之前,我以为你在问关于数据帧的问题,所以我很快就开始了,我对编码很陌生,很抱歉,我在这一点上帮不上忙代码工作正常,我只是想知道如何扩展代码(特别是那一行)。无论你的回答是什么都很有帮助,谢谢!非常感谢。你能解释一下吗。我认为如果isinstance(cell['Value'],(int,float))行只包括带有数字的行?