我有一个包含学校类型及其位置的数据框架。其中一栏是"Institude_Type“,两种学校类型是”中学(非文法)学校“和”中学(文法)学校“。我想把中学(非文法)学校的所有信息放到另一个数据框中--但我不确定该怎么做。
我希望它是当前DF的精确副本,具有所有相同的8列。一个是文法学校,另一个是非文法学校。
提前谢谢。
发布于 2017-12-07 02:11:17
使用内置的复制功能:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.copy.html
例如:
schoolCopy = schoolDataFrame[allTheColumnsRequired].copy(deep=True)发布于 2019-07-30 04:36:43
之前的堆栈溢出答案应该会有所帮助:
create a new dataframe from selecting specific rows from existing dataframe python
这个过程需要一个布尔运算符,以便它只应用于条件为真的数据帧的一部分。这需要[]中的()。
代码:
df2 = df[(df['Institude_Type'] == 'Secondary (non-grammar) School')]
df3 = df[(df['Institude_Type'] == 'Secondary (grammar) School')]
https://stackoverflow.com/questions/47680732
复制相似问题