简体   繁体   English

如何从数据框中消除行名和列名的值导致pyspark?

[英]How to eliminate row and column name values from the dataframe result in pyspark?

Hi i am loading a csv file into data frame, and running a filter operation on the data frame, and i am getting output as below 嗨,我正在将一个csv文件加载到数据帧,并在数据帧上运行筛选操作,我得到如下输出

[Row(table_name=u'DEMO', rec_count=u'170049', col_count=u'36')]

How can i get the output like below 我如何获得如下输出

`['DEMO','170049','36']`

i tried uni-coding and i can use for loop to iterate the data but problem the data is dynamic some time i get more than three values but i want to automate the process but i am unable to get the data as above 我尝试了uni编码,我可以使用for循环来迭代数据,但是问题是数据有时是动态的,我得到了三个以上的值,但是我想使过程自动化,但是我无法如上

You have a list whose element is a Row object; 您有一个列表,其元素为Row对象; You could use a keys list to define the columns and corresponding order you need in the result and then extract them from the Row object with a list comprehension: 您可以使用键列表来定义结果中所需的列和相应顺序,然后使用列表理解从Row对象中提取它们:

# this is what you have now
x = [Row(table_name=u'DEMO', rec_count=u'170049', col_count=u'36')]

keys = ['table_name', 'rec_count', 'col_count']
[x[0][key] for key in keys]
# [u'DEMO', u'170049', u'36']

暂无
暂无

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

相关问题 如何消除 PySpark DataFrame 列中条目的第一个字符? - How to eliminate the first characters of entries in a PySpark DataFrame column? 如何在 Pandas Dataframe 中基于多个 if,elif 语句填充列的每一行值时消除循环 - How to Eliminate for loop in Pandas Dataframe in filling each row values of a column based on multiple if,elif statements 在 PySpark 中 - 如果列表中的值位于不同的 DataFrame 的行中,如何在 PySpark 中创建新的 DataFrame? - In PySpark - How to create a new DataFrame in PySpark if values from list are in row of a different DataFrame? 如何将行从 pyspark 中的 dataframe 转换为列但保留列名? - pyspark 或 python - How can I convert a row from a dataframe in pyspark to a column but keep the column names? - pyspark or python 如何从 Pyspark Dataframe 中的字符串列中过滤字母值? - How to filter alphabetic values from a String column in Pyspark Dataframe? Pyspark DataFrame - 如何将一列从分类值转换为整数? - Pyspark DataFrame - How to convert one column from categorical values to int? 如何从pyspark数据帧中将列值输出为字符串? - How to output column values from pyspark dataframe into string? 如何将pyspark数据帧列中的值与pyspark中的另一个数据帧进行比较 - How to compare values in a pyspark dataframe column with another dataframe in pyspark Pyspark从数据框中的列中删除空值 - Pyspark Removing null values from a column in dataframe 如何在pyspark中重命名数据框的列名? - how to rename column name of dataframe in pyspark?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM