![](/img/trans.png)
[英]How to eliminate the first characters of entries in a PySpark DataFrame column?
[英]How to eliminate row and column name values from the dataframe result in pyspark?
嗨,我正在將一個csv文件加載到數據幀,並在數據幀上運行篩選操作,我得到如下輸出
[Row(table_name=u'DEMO', rec_count=u'170049', col_count=u'36')]
我如何獲得如下輸出
`['DEMO','170049','36']`
我嘗試了uni編碼,我可以使用for循環來迭代數據,但是問題是數據有時是動態的,我得到了三個以上的值,但是我想使過程自動化,但是我無法如上
您有一個列表,其元素為Row對象; 您可以使用鍵列表來定義結果中所需的列和相應順序,然后使用列表理解從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.