简体   繁体   English

为什么 DF 有时会自动更新,有时不会?

[英]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.

相关问题 为什么 selenium 有时会定位对象,有时则不会? - Why does sometimes selenium locate objects and sometimes no? 为什么 df1= df 不在 python 中复制数据帧? - why does df1= df does not copy a dataframe in python? 为什么 df[df['column'].max()] 不返回一行? - Why does df[df['column'].max()] does not a return a row? 为什么 DataFrame 行选择语法 df[:2] 有效,但如果语法 df[1] 无效? - Why does DataFrame row selection syntax df[:2] work but not if the syntax df[1]? 为什么sum(DF)与DF.sum()的行为不同? - Why does sum(DF) behave differently from DF.sum()? 将列添加到基于同一 DF 中其他两个列的值在 DF 中进行查找的 Pandas DF - Add column to pandas DF that does a lookup within the DF based on values of two other columns in the same DF 为什么另一个目录中文件的路径有时以“./”开头,有时以“../”开头 - Why does the path to a file in another dir start sometimes with “./” and sometimes with “../” 为什么 max() 有时会返回 nan 有时会忽略它? - Why does max() sometimes return nan and sometimes ignores it? 为什么Python有时会将字符串升级为unicode,有时不会? - Why does Python sometimes upgrade a string to unicode and sometimes not? 为什么 jupyter 有时会打印格式化的 DataFrame,有时会打印为文本? - Why does jupyter sometimes print a DataFrame formatted and sometimes as text?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM