清空dataframe
时间: 2023-11-18 12:53:39 浏览: 149
清空一个DataFrame可以使用以下方法:
1. 使用空的DataFrame替换原有的DataFrame
df = pd.DataFrame() [1]
2. 使用drop方法删除所有行
df = df.drop(df.index) [1]
3. 使用空值替换所有值
df = df.replace(np.nan, '') [3]
以上是三种常用的清空DataFrame的方法,可以根据具体需求选择适合的方法进行操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Pandas 删除 DataFrame 列,就这么简单!](https://blog.csdn.net/devid008/article/details/130501921)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [dataframe删除数据的方法](https://blog.csdn.net/m0_60836361/article/details/129524322)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文