返回顶部

Pandas 复制 DataFrame

0

0/300

评论 1

Andre老师@小象学院

1.使用 pandas.DataFrame.copy() 方法复制 Pandas DataFrame import pandas as pd import numpy as np items_df = pd.DataFrame({ 'Id': [302, 504, 708], 'Cost': ["300", "400", "350"], }) deep_copy = items_df.copy() print("Original DataFrame before changing value in copy DataFrame:") print(items_df, "\n") print("Copy DataFrame before changing value in copy DataFrame:") print(deep_copy, "\n") deep_copy.loc[0, "Cost"] = np.nan print("Original DataFrame after changing value in copy DataFrame:") print(items_df, "\n") print("Copy DataFrame after changing value in copy DataFrame:") print(deep_copy, "\n") 输出: Original DataFrame before changing value in copy DataFrame: Id Cost 0 302 300 1 504 400 2 708 350 Copy DataFrame before changing value in copy DataFrame: Id Cost 0 302 3

2021-11-22 18:21:48

- 没有更多了 -