Renaming columns using geopandas - issues with data table in Arc
What I'm trying to achieve:
- Read in an existing ESRI polygon shapefile
- Drop an attribute
- Dissolve by another attribute
- Rename columns
- Reorder columns
- Write out as new shapefile
What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.
Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:
Loading table data
Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.
A column was specified that doesn't exists.
A column was specified that doesn't exists.
So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?
import geopandas as gp
# Read data in
f="my_file"
data = gp.read_file(f)
# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)
# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)
# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns={"Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1"})
# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]
# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)
python shapefile geopandas
add a comment |
What I'm trying to achieve:
- Read in an existing ESRI polygon shapefile
- Drop an attribute
- Dissolve by another attribute
- Rename columns
- Reorder columns
- Write out as new shapefile
What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.
Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:
Loading table data
Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.
A column was specified that doesn't exists.
A column was specified that doesn't exists.
So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?
import geopandas as gp
# Read data in
f="my_file"
data = gp.read_file(f)
# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)
# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)
# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns={"Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1"})
# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]
# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)
python shapefile geopandas
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back
– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue
– Paul H
8 hours ago
@PaulH i beliveindex=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.
– BERA
8 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago
add a comment |
What I'm trying to achieve:
- Read in an existing ESRI polygon shapefile
- Drop an attribute
- Dissolve by another attribute
- Rename columns
- Reorder columns
- Write out as new shapefile
What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.
Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:
Loading table data
Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.
A column was specified that doesn't exists.
A column was specified that doesn't exists.
So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?
import geopandas as gp
# Read data in
f="my_file"
data = gp.read_file(f)
# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)
# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)
# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns={"Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1"})
# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]
# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)
python shapefile geopandas
What I'm trying to achieve:
- Read in an existing ESRI polygon shapefile
- Drop an attribute
- Dissolve by another attribute
- Rename columns
- Reorder columns
- Write out as new shapefile
What works: Drop column and dissolve all work - I've run these steps and written to file. This opens fine in ArcMap, I can identify things, open the attribute table etc. No issues.
Problem: When I rename (not got to the reorder step without error yet) the columns, everything runs fine and I write to file. When then opening the shapefile in ArcMap (10.3.1) I can query layers using the Identify cursor which shows my renamed attributes as they should be BUT when trying to open the attribute table, I get the following message in a window:
Loading table data
Could not load data from the data source. If you can correct the problem, press the refresh button to reload data. Possible problems can include bad network connection, invalid file, etc.
A column was specified that doesn't exists.
A column was specified that doesn't exists.
So, it looks like something is missing or my changes are not being mapped across the shapefile components. I can't share the data but can share the code. The problem is with the renaming... What am I missing?
import geopandas as gp
# Read data in
f="my_file"
data = gp.read_file(f)
# Drop a column (if writing out file here, does as expected)
data=data.drop(['CLASS'], axis=1)
# Do the dissolve (if writing out file here, does as expected)
data=data.dissolve(by='Hazard_Pot', as_index=False)
# Rename (THE PROBLEM I THINK : if saving here, I get my issue in ArcMap)
data=data.rename(index=str, columns={"Hazard_Pot":"Potential",
"casualties":"Casualty",
"vehicle_ac":"Access",
"building d":"Damage",
"disruption":"Disruption",
"contaminat":"Contam.",
"do_not_1":"Do_Not_1"})
# Reorder
data=data[['Potential',
'Casualty',
'Access',
'Damage',
'Disruption',
'Contam.',
'Do_Not_1',
'geometry']]
# write to file (creating a new CRS based on the old as per https://gis.stackexchange.com/questions/204201/geopandas-to-file-saves-geodataframe-without-coordinate-system?noredirect=1&lq=1)
prj_file = "%s.prj" %os.path.splitext(f)[0]
prj = [l.strip() for l in open(prj_file,'r')][0]
data.to_file(ofile, driver=driver, crs_wkt=prj)
python shapefile geopandas
python shapefile geopandas
asked 8 hours ago
ChrisWillsChrisWills
506
506
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back
– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue
– Paul H
8 hours ago
@PaulH i beliveindex=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.
– BERA
8 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago
add a comment |
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back
– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue
– Paul H
8 hours ago
@PaulH i beliveindex=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.
– BERA
8 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back– Paul H
8 hours ago
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue– Paul H
8 hours ago
@PaulH i belive
index=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.– BERA
8 hours ago
@PaulH i belive
index=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.– BERA
8 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Looking at your code I can see two things that Arcmap doesn't like:
- The first one is the space in the field name
"building d"
; - The second one - and the cause of the error - is the
.
in"contaminat":"Contam."
.
I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam"
solved the problem.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f316876%2frenaming-columns-using-geopandas-issues-with-data-table-in-arc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Looking at your code I can see two things that Arcmap doesn't like:
- The first one is the space in the field name
"building d"
; - The second one - and the cause of the error - is the
.
in"contaminat":"Contam."
.
I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam"
solved the problem.
New contributor
add a comment |
Looking at your code I can see two things that Arcmap doesn't like:
- The first one is the space in the field name
"building d"
; - The second one - and the cause of the error - is the
.
in"contaminat":"Contam."
.
I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam"
solved the problem.
New contributor
add a comment |
Looking at your code I can see two things that Arcmap doesn't like:
- The first one is the space in the field name
"building d"
; - The second one - and the cause of the error - is the
.
in"contaminat":"Contam."
.
I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam"
solved the problem.
New contributor
Looking at your code I can see two things that Arcmap doesn't like:
- The first one is the space in the field name
"building d"
; - The second one - and the cause of the error - is the
.
in"contaminat":"Contam."
.
I was able to reproduce the error by creating a test file and using your code. Removing the dot "contaminat":"Contam"
solved the problem.
New contributor
New contributor
answered 8 hours ago
Mouad AlamiMouad Alami
994
994
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f316876%2frenaming-columns-using-geopandas-issues-with-data-table-in-arc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
data.rename(index=str...
renaming the index to a data type is very strange. Take that part out and report back– Paul H
8 hours ago
I can't share the data but can share the code
and you can share fake data that reproduces the issue– Paul H
8 hours ago
@PaulH i belive
index=str
is correct syntax, see the examples in help section of rename. But I also think that part is not needed.– BERA
8 hours ago
@BERA Oops - forgot rename could take callables.
– Paul H
7 hours ago