简体   繁体   English

选择用于复制 Pandas DataFrame 的列

[英]Selecting columns for copying Pandas DataFrame

I would like to copy my existing df to another pandas dataframe.我想将我现有的df复制到另一个 Pandas 数据框。 Basically if I need to specify columns and copy-then it's easy and can be done in such a manner:基本上,如果我需要指定列和复制,那么这很容易并且可以通过以下方式完成:

df_copy = df[['col_A', 'col_B', 'col_C']].copy()

But is it possible to copy only the other columns which not specified using this approach?但是是否可以仅复制未使用此方法指定的其他列? I tried that way but it seems to be wrong:我试过这种方式,但似乎是错误的:

df_copy = df[~df['col_A', 'col_B', 'col_C']].copy()

Thanks in advance!提前致谢!

df.columns.isin()前面的否定如何~

df_copy_not = df[df.columns[~df.columns.isin(['col_A', 'col_B', 'col_C'])]]

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

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