如何更改列的标头,以便我可以将其与另一个数据集一起加入?

发布于 2025-01-31 17:28:13 字数 3346 浏览 3 评论 0原文

我正在尝试将数据集加入另一个数据集,以便我可以执行空间分析。两个数据集都有可以连接的列,但一个是用大写字母写的,另一个是小写的。我需要更改标题的编写方式还是可以以另一种方式加入专栏?

london = gpd.read_file('https://github.com/cusp-london/Spatial-Data-Analysis/blob/master/LDN-LSOAs.zip?raw=true')
london

lsoa11cd    lsoa11nm    lsoa11nmw   objectid    st_areasha  st_lengths  geometry
0   E01000001   City of London 001A City of London 001A 1   133,320.7689    2,291.8461  POLYGON ((532105.330 182017.386, 532162.728 18...
1   E01000002   City of London 001B City of London 001B 2   226,191.2730    2,433.9601  POLYGON ((532747.048 181793.042, 532671.921 18...
2   E01000003   City of London 001C City of London 001C 3   57,302.9665 1,142.3598  POLYGON ((532135.385 182204.275, 532158.489 18...
3   E01000005   City of London 001E City of London 001E 4   190,738.7605    2,167.8683  POLYGON ((533808.170 180773.910, 533649.287 18...
4   E01000006   Barking and Dagenham 016A   Barking and Dagenham 016A   5   144,195.8469    1,935.5104  POLYGON ((545122.084 184321.013, 545271.951 18...
... ... ... ... ... ... ... ...
4830    E01033742   Greenwich 007F  Greenwich 007F  32818   123,309.1855    1,860.3102  POLYGON ((544642.760 179830.773, 544766.392 17...
4831    E01033743   Greenwich 002H  Greenwich 002H  32819   1,004,853.0874  5,237.1802  POLYGON ((546579.271 181103.898, 546687.117 18...
4832    E01033744   Greenwich 007G  Greenwich 007G  32820   152,261.9933    2,149.3709  POLYGON ((544536.564 179453.221, 544602.707 17...
4833    E01033745   Greenwich 002I  Greenwich 002I  32821   558,477.7026    4,193.8283  POLYGON ((546415.827 180158.362, 546320.798 18...
4834    E01033746   Greenwich 038E  Greenwich 038E  32822   128,976.6864    2,367.4053  POLYGON ((538140.138 177319.110, 538129.314 17...
4835 rows × 7 columns

ptal_lsoas

geometry    LSOA11CD    AvPTAI2015  PTAL    PTAIHigh    PTAILow
0   POLYGON ((532105.092 182011.230, 532162.491 18...   E01000001   69.8233 6b  97.4435 35.9190
1   POLYGON ((532746.813 181786.891, 532671.688 18...   E01000002   83.7820 6b  117.9120    66.3503
2   POLYGON ((532135.145 182198.119, 532158.250 18...   E01000003   41.7417 6b  49.5318 37.3635
3   POLYGON ((533807.946 180767.770, 533649.063 18...   E01000005   85.8893 6b  120.8470    45.9168
4   POLYGON ((545122.049 184314.931, 545271.917 18...   E01000006   22.4558 5   34.1054 0.0000
... ... ... ... ... ... ...
4830    POLYGON ((544642.680 179824.674, 544766.313 17...   E01033742   3.9532  1b  5.7986  3.0585
4831    POLYGON ((546579.195 181097.813, 546687.036 18...   E01033743   3.8174  1b  14.3944 0.0000
4832    POLYGON ((544536.486 179447.115, 544602.630 17...   E01033744   10.1709 3   23.5689 3.5750
4833    POLYGON ((546415.745 180152.270, 546320.715 18...   E01033745   4.6838  1b  11.4851 0.0000
4834    POLYGON ((538140.000 177313.000, 538129.177 17...   E01033746   18.9882 4   24.1235 14.5436
4835 rows × 6 columns

我还试图通过“几何”列加入他们,但没有预先显示的数据,

geo_ptal_lsoas = pd.merge (london, ptal_lsoas, left_on = ['geometry'],
                  right_on = ['geometry'],
                  how = 'inner')

geo_ptal_lsoas

lsoa11cd_x  lsoa11nm_x  lsoa11nmw_x objectid_x  st_areasha_x    st_lengths_x    geometry    lsoa11cd_y  lsoa11nm_y  lsoa11nmw_y objectid_y  st_areasha_y    st_lengths_y    LSOA11CD    AvPTAI2015  PTAL    PTAIHigh    PTAILow

请提前显示!

I'm trying to join a dataset to another so i can perform spatial analysis. Both datasets have columns which can be joined, but one is written in capital letters and the other lowercase. Do I need to change the way the header is written or can I join the columns another way?

london = gpd.read_file('https://github.com/cusp-london/Spatial-Data-Analysis/blob/master/LDN-LSOAs.zip?raw=true')
london

lsoa11cd    lsoa11nm    lsoa11nmw   objectid    st_areasha  st_lengths  geometry
0   E01000001   City of London 001A City of London 001A 1   133,320.7689    2,291.8461  POLYGON ((532105.330 182017.386, 532162.728 18...
1   E01000002   City of London 001B City of London 001B 2   226,191.2730    2,433.9601  POLYGON ((532747.048 181793.042, 532671.921 18...
2   E01000003   City of London 001C City of London 001C 3   57,302.9665 1,142.3598  POLYGON ((532135.385 182204.275, 532158.489 18...
3   E01000005   City of London 001E City of London 001E 4   190,738.7605    2,167.8683  POLYGON ((533808.170 180773.910, 533649.287 18...
4   E01000006   Barking and Dagenham 016A   Barking and Dagenham 016A   5   144,195.8469    1,935.5104  POLYGON ((545122.084 184321.013, 545271.951 18...
... ... ... ... ... ... ... ...
4830    E01033742   Greenwich 007F  Greenwich 007F  32818   123,309.1855    1,860.3102  POLYGON ((544642.760 179830.773, 544766.392 17...
4831    E01033743   Greenwich 002H  Greenwich 002H  32819   1,004,853.0874  5,237.1802  POLYGON ((546579.271 181103.898, 546687.117 18...
4832    E01033744   Greenwich 007G  Greenwich 007G  32820   152,261.9933    2,149.3709  POLYGON ((544536.564 179453.221, 544602.707 17...
4833    E01033745   Greenwich 002I  Greenwich 002I  32821   558,477.7026    4,193.8283  POLYGON ((546415.827 180158.362, 546320.798 18...
4834    E01033746   Greenwich 038E  Greenwich 038E  32822   128,976.6864    2,367.4053  POLYGON ((538140.138 177319.110, 538129.314 17...
4835 rows × 7 columns

ptal_lsoas

geometry    LSOA11CD    AvPTAI2015  PTAL    PTAIHigh    PTAILow
0   POLYGON ((532105.092 182011.230, 532162.491 18...   E01000001   69.8233 6b  97.4435 35.9190
1   POLYGON ((532746.813 181786.891, 532671.688 18...   E01000002   83.7820 6b  117.9120    66.3503
2   POLYGON ((532135.145 182198.119, 532158.250 18...   E01000003   41.7417 6b  49.5318 37.3635
3   POLYGON ((533807.946 180767.770, 533649.063 18...   E01000005   85.8893 6b  120.8470    45.9168
4   POLYGON ((545122.049 184314.931, 545271.917 18...   E01000006   22.4558 5   34.1054 0.0000
... ... ... ... ... ... ...
4830    POLYGON ((544642.680 179824.674, 544766.313 17...   E01033742   3.9532  1b  5.7986  3.0585
4831    POLYGON ((546579.195 181097.813, 546687.036 18...   E01033743   3.8174  1b  14.3944 0.0000
4832    POLYGON ((544536.486 179447.115, 544602.630 17...   E01033744   10.1709 3   23.5689 3.5750
4833    POLYGON ((546415.745 180152.270, 546320.715 18...   E01033745   4.6838  1b  11.4851 0.0000
4834    POLYGON ((538140.000 177313.000, 538129.177 17...   E01033746   18.9882 4   24.1235 14.5436
4835 rows × 6 columns

i have also tried to join them via the 'geometry' column but am met with no data showing

geo_ptal_lsoas = pd.merge (london, ptal_lsoas, left_on = ['geometry'],
                  right_on = ['geometry'],
                  how = 'inner')

geo_ptal_lsoas

lsoa11cd_x  lsoa11nm_x  lsoa11nmw_x objectid_x  st_areasha_x    st_lengths_x    geometry    lsoa11cd_y  lsoa11nm_y  lsoa11nmw_y objectid_y  st_areasha_y    st_lengths_y    LSOA11CD    AvPTAI2015  PTAL    PTAIHigh    PTAILow

thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2025-02-07 17:28:13

使用:

ptal_lsoas.columns = ptal_lsoas.columns.str.lower()

Covert the columns of your second dataframe to lowercase using:

ptal_lsoas.columns = ptal_lsoas.columns.str.lower()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文