【发布时间】:2020-10-27 23:09:34
【问题描述】:
我知道有一百万篇关于 Pandas DataFrame 复制切片警告的帖子,我对此进行了研究......但我仍然不明白为什么下面的第 10 行没有调用警告,但下面的第 15 行调用了警告。使用 Python 3.8.3 和 pandas 1.0.5
import pandas as pd
#### Example DataFrame
myid = [1, 1, 1, 2, 2]
myorder = [3, 2, 1, 2, 1]
y = [3642, 3640, 3632, 3628, 3608]
x = [11811, 11812, 11807, 11795, 11795]
df = pd.DataFrame(list(zip(myid, myorder, x, y)),
columns =['myid', 'myorder', 'x', 'y'])
df.sort_values(by=['myid', 'myorder'], inplace=True) ## LINE 10
df.reset_index(drop=True, inplace=True)
idval =2
tempdf = df[mygdf.myid == idval]
tempdf.sort_values(by=['myid', 'myorder'], inplace=True) ## LINE 15
tempdf.reset_index(drop=True, inplace=True)
【问题讨论】:
标签: python-3.x pandas