简体   繁体   English

熊猫:如何通过变量(列)将数据框分为两个数据框?

[英]Pandas: How to split a dataframe into two dataframes by variables (columns)?

I have dataframe with columns "Weight", "Rank", "Country", and "Age", ... and several more columns and I need to split the dataframe into continuous variable columns (ie weight, age, ) and discrete variable columns. 我有带有“重量”,“排名”,“国家”和“年龄”等列的数据框,还有其他几列,我需要将数据框分成连续的可变列(即体重,年龄,)和离散变量列。

I was hoping to divide the dataframe into two separate dataframes by column names. 我希望按列名将数据框分为两个单独的数据框。 Is this possible? 这可能吗?

df = #your dataframe

df1 = df[['Weight','Age']].copy()

df2 = df[['Rank','Country']].copy()

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM