I have a subset of dataframe x
>> x.loc[1030:1036,'Priority order':]
Priority order|bike_id| lat| lon| median_idle_time
| | |
|1030| 1 | 52447| 13.027514 77.723228 31.904444
|1031| 1 | 52447| 13.027514 77.723228 31.904444
|1032| 1 | 52447| 13.027514 77.723228 31.904444
|1033| 1 | 52447| 13.027514 77.723228 31.904444
|1034| 1 | 52447| 13.027514 77.723228 31.904444
|1035| 1 | 52447| 13.027514 77.723228 31.904444
|1036| 1 | 52447| 13.027514 77.723228 31.904444
when i try to change it with another subset of same parent Dataframe x
>> x.loc[157:330,'Priority order':'median_idle_time']
| |Priority |bike_id |lat |lon |median_idle_time
order
|157 |158 51281 13.053876 77.550079 2.017778
|158 |159 53283 12.975240 77.479927 2.004306
|159 |160 48387 12.824695 77.673805 2.000556
|160 |161 52320 12.993121 77.576515 1.984722
|161 |162 35281 12.934137 77.686356 1.958333
|... |... ... ... ... ...
|326 |327 48103 12.985148 77.618721 0.464167
|327 |328 48577 12.959455 77.651382 0.443611
|328 |329 54039 12.982092 77.639412 0.311944
|329 |330 49586 13.011577 77.607353 0.213889
|330 |331 53100 12.971110 77.640602 0.199167
x.loc[1030:1036,'Priority order':'median_idle_time'] = x.loc[157:330,'Priority order':'median_idle_time']
is giving me NaN value at subset location of dataframe x
|Priority |drop hex |avg_daily_sessions |idle_bike_count |drop lat |drop lon |avg_daily_sessions/supply |Priority order |bike_id |lat |lon |median_idle_time
|0 | 1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |1.0 |52447.0 |13.027514 |77.723228 |31.904444
|1030 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1031 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1032 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1033 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1034 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1035 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
|1036 |1 |8960144b4dbffff |122.071429 |0 |13.084574 |77.48569 |122.071429 |NaN |NaN |NaN |NaN |NaN
Would appreciate if anyone could point out where i am messing up the things?
CodePudding user response:
Two problems in this line x.loc[1030:1036,'Priority order':'median_idle_time'] = x.loc[157:330,'Priority order':'median_idle_time']
#1, their shapes do not match. L.H.S. has 7 rows but R.H.S. has 174 rows. Please match them.
#2, pandas assigns value index-wise, and because there is no index-overlap between the L.H.S. and the R.H.S., you see all those NaN
. You may convert the R.H.S. to an array by x.loc[157:330,'Priority order':'median_idle_time'].values