我正在尝试使用列列表从csv数据框中选择数据列,然后将提取的数据保存到另一个csv_file中。
columns_to_extract = model.columns # 'Name', 'Age', 'Address', 'Sex' FORM the model database
df = pd.read_csv('some-data.csv', encoding='ISO-8859-1')
df = df[[columns_to_extract]] # this doesn't work
# also tried df = df[[columns_to_extract.split(',)]] and didn't work too
import StringIO
s_df = StringIO.StringIO()
df.to_csv(s_df)