NaN 即将覆盖 pandas 中相同数据帧的另一个子集的数据帧子集
NaN coming on overwriting subset of dataframe from another subset of same dataframe in pandas
我有一个数据帧的子集 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
当我尝试用同一父 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']
在数据框 x
的子集位置给我 NaN 值
|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
如果有人能指出我哪里搞砸了,我将不胜感激?
这一行有两个问题x.loc[1030:1036,'Priority order':'median_idle_time'] = x.loc[157:330,'Priority order':'median_idle_time']
#1,它们的形状不匹配。 L.H.S。有 7 行,但 R.H.S。有 174 行。请匹配它们。
#2,pandas赋值index-wise,因为L.H.S之间没有index-overlap。和 R.H.S.,你会看到所有这些 NaN
。您可以转换 R.H.S。通过 x.loc[157:330,'Priority order':'median_idle_time'].values
到数组
我有一个数据帧的子集 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
当我尝试用同一父 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']
在数据框 x
的子集位置给我 NaN 值 |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
如果有人能指出我哪里搞砸了,我将不胜感激?
这一行有两个问题x.loc[1030:1036,'Priority order':'median_idle_time'] = x.loc[157:330,'Priority order':'median_idle_time']
#1,它们的形状不匹配。 L.H.S。有 7 行,但 R.H.S。有 174 行。请匹配它们。
#2,pandas赋值index-wise,因为L.H.S之间没有index-overlap。和 R.H.S.,你会看到所有这些 NaN
。您可以转换 R.H.S。通过 x.loc[157:330,'Priority order':'median_idle_time'].values