0

While I am using pandas.DataFrame, when I want to inverse whole Column Value, I find that they are different when I use DF.loc[wInd, 'Column'] and DF.loc[:, 'Column'], where the 1st case exchanges the value, but 2nd case gives me same column value. Why are they different? Thank you.

wInd = LineCircPart_df.index
for cWd in ['X', 'Y', 'Angle']:
    (LineCircPart_df.loc[wInd,f'Start{cWd}'], LineCircPart_df.loc[wInd,f'End{cWd}']) = 
    (LineCircPart_df.loc[wInd, f'End{cWd}'], LineCircPart_df.loc[wInd,f'Start{cWd}'])

and i need to modified with .copy() for the value assigned to, like:

wInd = LineCircPart_df.index
for cWd in ['X', 'Y', 'Angle']:
    LineCircPart_df.loc[:,f'Start{cWd}'], LineCircPart_df.loc[:,f'End{cWd}'] = 
    (LineCircPart_df.loc[:, f'End{cWd}'].copy(), LineCircPart_df.loc[:,f'Start{cWd}'].copy())

Any Suggestions?

Example updated as follows:

LineCircPart_df = pd.DataFrame({'StartX': [3000, 4000, 5000], 'StartY': [30, 40, 50], 'StartAngle': [3, 4, 5], 'EndX': [6000, 7000, 8000], 'EndY': [60, 70, 80], 'EndAngle': [6, 7, 8],})
for cWd in ['X', 'Y', 'Angle']:
   (LineCircPart_df.loc[:,f'Start{cWd}'], LineCircPart_df.loc[:,f'End{cWd}']) = (LineCircPart_df.loc[:, f'End{cWd}'],LineCircPart_df.loc[:,f'Start{cWd}'])
HA HA chan
  • 123
  • 1
  • 9
  • 2
    Please provide [`minimal reproducible example`](https://stackoverflow.com/q/20109391/4985099) – sushanth Aug 23 '20 at 06:32
  • specifically, we want to run the code you provide; currently, many variables are not defined in your code – anon01 Aug 23 '20 at 08:52

0 Answers0