I think you need copy
:
train = df.loc[df['group'] != i].copy()
test = df.loc[df['group'] == i].copy()
If you modify values in test
later you will find that the modifications do not propagate back to the original data (df
), and that Pandas does warning.
More Related Contents:
- Select nan column in pandas
- How to identify and label similar rows in a pandas data frame
- How do I read a large csv file with pandas?
- How can I use the apply() function for a single column?
- Pandas filtering for multiple substrings in series
- Remove duplicates by columns A, keeping the row with the highest value in column B
- Python pandas insert list into a cell
- Pandas DataFrame Groupby two columns and get counts
- How can I display full (non-truncated) dataframe information in HTML when converting from Pandas dataframe to HTML?
- Pandas: conditional rolling count
- pandas: to_numeric for multiple columns
- group by pandas dataframe and select latest in each group
- Selection with .loc in python
- Access to table objects on Webpage Using Python Selenium
- How to flatten a hierarchical index in columns
- Check if string is in a pandas dataframe
- Most efficient way to sort an array into bins specified by an index array?
- Why is Apache-Spark – Python so slow locally as compared to pandas?
- splitting at underscore in python and storing the first value
- UnicodeDecodeError: (‘utf-8’ codec) while reading a csv file [duplicate]
- Transform vs. aggregate in Pandas
- NumPy version of “Exponential weighted moving average”, equivalent to pandas.ewm().mean()
- Split pandas dataframe based on values in a column using groupby
- How to remove decimal points in pandas
- FutureWarning: The default value of regex will change from True to False in a future version
- Pretty print a pandas dataframe in VS Code
- Transpose the data in a column every nth rows in PANDAS
- Why doesn’t my pandas rolling().apply() work when the series contains collections?
- Pandas Rolling Computations on Sliding Windows (Unevenly spaced)
- DataFrame object has no attribute append