[英]How to convert the following R code to Python code
該代碼刪除了表中不需要的列:
inputData <- inputData[,!(colnames(inputData) %in% c('col1','col2',''))]
需要幫助將此行轉換為 python,我正在努力解決它,因為我對 python 還很陌生;-;
假設您需要翻譯到第三方 Pandas,與 R 不同,數據框不是 Python 中的標准庫對象,請考慮Index.isin
替換%in%
和波浪號否定運算符~
替換!
:
inputData = inputData[
inputData.columns[~inputData.columns.isin(['col1','col2',''])]
]
或者,嘗試Index.difference
:
inputData = inputData[
inputData.columns.difference(['col1','col2',''])
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.