[英]Why does a DF sometimes automatically update, other times does NOT?
So, I'm unclear why doing certain operations on a DF updates it right away, but other times it does not update it unless you re-use the old name or use a new df variable name.所以,我不清楚为什么对 DF 执行某些操作会立即更新它,但有时它不会更新它,除非您重新使用旧名称或使用新的 df 变量名称。
Doesn't this make it really confusing where the last 'real' change is?这不会让最后一个“真正”变化的地方变得很混乱吗?
First of all, a df behaves like a list in python, meaning that if you make a soft copy of it and change it, the original df changes too.首先,df 的行为类似于 python 中的列表,这意味着如果您制作它的软副本并更改它,原始 df 也会更改。 To answer your question you must know that some methods of updating a df, write on a hard copy version of that df (which are indicated by a warning given by pandas letting you know that you are writing on a copy) so the data might not change.
要回答您的问题,您必须知道更新 df 的某些方法,请写在该 df 的硬拷贝版本上(由 Pandas 发出的警告指示,让您知道您正在写在副本上),因此数据可能不会改变。 the best and most reliable way to change data using pandas is either:
使用 Pandas 更改数据的最佳和最可靠的方法是:
df.at[a_cell] = some_data
or:或者:
df.loc[some_rows, some_columns] = some_data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.