Table to Table converting ArcMap table to CSV file in external location cuts column names short?
I am having a strange problem with the ArcPy Table to Table function. For some reason, when I use the function to create a CSV file in a folder that exists outside of my python project folder, several columns in the CSV file have their headers cut short. For example, I have a column titled "PASSING_400_MICROM" that gets truncated to "PASSING_400_MICR'.
Thus far, I have discovered the following about the problem:
- The truncation of the same column headers appear to occur in any folder, both on my shared network and local machine, that isn't the python project folder. All the headers are truncated to 16 characters in length.
- No truncation occurs if I place the CSV within my project file. (However, I can't do this for the final code, as people on other computers will use my code)
I've done a lot of searching, and I still don't understand why this is happening and how to fix it. I am relatively new to Python and ArcGIS, so I don't even know if I'm searching for the correct things.
What might be causing this problem, and how I can fix it?
Here is an example of the function I am using:
arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
out_path=CSVLocation,
out_name='Table.csv',
where_clause=whereclause)
arcpy csv table
New contributor
add a comment |
I am having a strange problem with the ArcPy Table to Table function. For some reason, when I use the function to create a CSV file in a folder that exists outside of my python project folder, several columns in the CSV file have their headers cut short. For example, I have a column titled "PASSING_400_MICROM" that gets truncated to "PASSING_400_MICR'.
Thus far, I have discovered the following about the problem:
- The truncation of the same column headers appear to occur in any folder, both on my shared network and local machine, that isn't the python project folder. All the headers are truncated to 16 characters in length.
- No truncation occurs if I place the CSV within my project file. (However, I can't do this for the final code, as people on other computers will use my code)
I've done a lot of searching, and I still don't understand why this is happening and how to fix it. I am relatively new to Python and ArcGIS, so I don't even know if I'm searching for the correct things.
What might be causing this problem, and how I can fix it?
Here is an example of the function I am using:
arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
out_path=CSVLocation,
out_name='Table.csv',
where_clause=whereclause)
arcpy csv table
New contributor
1
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago
add a comment |
I am having a strange problem with the ArcPy Table to Table function. For some reason, when I use the function to create a CSV file in a folder that exists outside of my python project folder, several columns in the CSV file have their headers cut short. For example, I have a column titled "PASSING_400_MICROM" that gets truncated to "PASSING_400_MICR'.
Thus far, I have discovered the following about the problem:
- The truncation of the same column headers appear to occur in any folder, both on my shared network and local machine, that isn't the python project folder. All the headers are truncated to 16 characters in length.
- No truncation occurs if I place the CSV within my project file. (However, I can't do this for the final code, as people on other computers will use my code)
I've done a lot of searching, and I still don't understand why this is happening and how to fix it. I am relatively new to Python and ArcGIS, so I don't even know if I'm searching for the correct things.
What might be causing this problem, and how I can fix it?
Here is an example of the function I am using:
arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
out_path=CSVLocation,
out_name='Table.csv',
where_clause=whereclause)
arcpy csv table
New contributor
I am having a strange problem with the ArcPy Table to Table function. For some reason, when I use the function to create a CSV file in a folder that exists outside of my python project folder, several columns in the CSV file have their headers cut short. For example, I have a column titled "PASSING_400_MICROM" that gets truncated to "PASSING_400_MICR'.
Thus far, I have discovered the following about the problem:
- The truncation of the same column headers appear to occur in any folder, both on my shared network and local machine, that isn't the python project folder. All the headers are truncated to 16 characters in length.
- No truncation occurs if I place the CSV within my project file. (However, I can't do this for the final code, as people on other computers will use my code)
I've done a lot of searching, and I still don't understand why this is happening and how to fix it. I am relatively new to Python and ArcGIS, so I don't even know if I'm searching for the correct things.
What might be causing this problem, and how I can fix it?
Here is an example of the function I am using:
arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
out_path=CSVLocation,
out_name='Table.csv',
where_clause=whereclause)
arcpy csv table
arcpy csv table
New contributor
New contributor
edited 3 hours ago
PolyGeo♦
53.4k1780239
53.4k1780239
New contributor
asked 3 hours ago
The Querying InternThe Querying Intern
262
262
New contributor
New contributor
1
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago
add a comment |
1
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago
1
1
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
As a workaround, you could write out the csv file yourself:
import os, csv
import arcpy
def table_to_csv(table, csv_file, fields, where_clause=None):
""" Example to export a table or feature class attribute table to CSV"""
with open(csv_file, 'wb') as csv_file_obj, arcpy.da.SearchCursor(table, fields, where_clause=where_clause) as rows:
csv_writer = csv.writer(csv_file_obj)
csv_writer.writerow(rows.fields)
for row in rows:
csv_writer.writerow(row)
# Rest of your code etc...
# arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
# out_path=CSVLocation,
# out_name='Table.csv',
# where_clause=whereclause)
table_to_csv(os.path.join(DatabaseLocation, 'Table'),
os.path.join(CSVLocation,'Table.csv'),
['field1', 'field2'],
whereclause)
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
add a comment |
I just tried this in 10.6.1 running on Windows 10. I added a test field called "PASSING_400_MICROM" and set all values to be "YES". When I went to tun the Table to Table tool and set the output to be a CSV file it truncated the field name to 11 characters. I tried editing the field map and it set it back to 11 characters.
My gut feeling is that this tool is imposing some sort of field name limitation, like it or not.
At this point I would suggest you head over to the ESRI Code Sharing website, the first place of call for user created tools, be it from the community at large or an ESRI development team. I have used the Excel and CSV Conversion Toolbox when needing to convert to CSV because of the flakiness of the Table to Table tool.
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
});
}
});
The Querying Intern is a new contributor. Be nice, and check out our Code of Conduct.
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%2f311159%2ftable-to-table-converting-arcmap-table-to-csv-file-in-external-location-cuts-col%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As a workaround, you could write out the csv file yourself:
import os, csv
import arcpy
def table_to_csv(table, csv_file, fields, where_clause=None):
""" Example to export a table or feature class attribute table to CSV"""
with open(csv_file, 'wb') as csv_file_obj, arcpy.da.SearchCursor(table, fields, where_clause=where_clause) as rows:
csv_writer = csv.writer(csv_file_obj)
csv_writer.writerow(rows.fields)
for row in rows:
csv_writer.writerow(row)
# Rest of your code etc...
# arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
# out_path=CSVLocation,
# out_name='Table.csv',
# where_clause=whereclause)
table_to_csv(os.path.join(DatabaseLocation, 'Table'),
os.path.join(CSVLocation,'Table.csv'),
['field1', 'field2'],
whereclause)
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
add a comment |
As a workaround, you could write out the csv file yourself:
import os, csv
import arcpy
def table_to_csv(table, csv_file, fields, where_clause=None):
""" Example to export a table or feature class attribute table to CSV"""
with open(csv_file, 'wb') as csv_file_obj, arcpy.da.SearchCursor(table, fields, where_clause=where_clause) as rows:
csv_writer = csv.writer(csv_file_obj)
csv_writer.writerow(rows.fields)
for row in rows:
csv_writer.writerow(row)
# Rest of your code etc...
# arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
# out_path=CSVLocation,
# out_name='Table.csv',
# where_clause=whereclause)
table_to_csv(os.path.join(DatabaseLocation, 'Table'),
os.path.join(CSVLocation,'Table.csv'),
['field1', 'field2'],
whereclause)
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
add a comment |
As a workaround, you could write out the csv file yourself:
import os, csv
import arcpy
def table_to_csv(table, csv_file, fields, where_clause=None):
""" Example to export a table or feature class attribute table to CSV"""
with open(csv_file, 'wb') as csv_file_obj, arcpy.da.SearchCursor(table, fields, where_clause=where_clause) as rows:
csv_writer = csv.writer(csv_file_obj)
csv_writer.writerow(rows.fields)
for row in rows:
csv_writer.writerow(row)
# Rest of your code etc...
# arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
# out_path=CSVLocation,
# out_name='Table.csv',
# where_clause=whereclause)
table_to_csv(os.path.join(DatabaseLocation, 'Table'),
os.path.join(CSVLocation,'Table.csv'),
['field1', 'field2'],
whereclause)
As a workaround, you could write out the csv file yourself:
import os, csv
import arcpy
def table_to_csv(table, csv_file, fields, where_clause=None):
""" Example to export a table or feature class attribute table to CSV"""
with open(csv_file, 'wb') as csv_file_obj, arcpy.da.SearchCursor(table, fields, where_clause=where_clause) as rows:
csv_writer = csv.writer(csv_file_obj)
csv_writer.writerow(rows.fields)
for row in rows:
csv_writer.writerow(row)
# Rest of your code etc...
# arcpy.TableToTable_conversion(in_rows=DatabaseLocation + '\Table',
# out_path=CSVLocation,
# out_name='Table.csv',
# where_clause=whereclause)
table_to_csv(os.path.join(DatabaseLocation, 'Table'),
os.path.join(CSVLocation,'Table.csv'),
['field1', 'field2'],
whereclause)
edited 21 mins ago
answered 2 hours ago
user2856user2856
29.5k256103
29.5k256103
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
add a comment |
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
+1 If you have any dates, you might need to write a schema.ini too.
– Kirk Kuykendall
28 mins ago
add a comment |
I just tried this in 10.6.1 running on Windows 10. I added a test field called "PASSING_400_MICROM" and set all values to be "YES". When I went to tun the Table to Table tool and set the output to be a CSV file it truncated the field name to 11 characters. I tried editing the field map and it set it back to 11 characters.
My gut feeling is that this tool is imposing some sort of field name limitation, like it or not.
At this point I would suggest you head over to the ESRI Code Sharing website, the first place of call for user created tools, be it from the community at large or an ESRI development team. I have used the Excel and CSV Conversion Toolbox when needing to convert to CSV because of the flakiness of the Table to Table tool.
add a comment |
I just tried this in 10.6.1 running on Windows 10. I added a test field called "PASSING_400_MICROM" and set all values to be "YES". When I went to tun the Table to Table tool and set the output to be a CSV file it truncated the field name to 11 characters. I tried editing the field map and it set it back to 11 characters.
My gut feeling is that this tool is imposing some sort of field name limitation, like it or not.
At this point I would suggest you head over to the ESRI Code Sharing website, the first place of call for user created tools, be it from the community at large or an ESRI development team. I have used the Excel and CSV Conversion Toolbox when needing to convert to CSV because of the flakiness of the Table to Table tool.
add a comment |
I just tried this in 10.6.1 running on Windows 10. I added a test field called "PASSING_400_MICROM" and set all values to be "YES". When I went to tun the Table to Table tool and set the output to be a CSV file it truncated the field name to 11 characters. I tried editing the field map and it set it back to 11 characters.
My gut feeling is that this tool is imposing some sort of field name limitation, like it or not.
At this point I would suggest you head over to the ESRI Code Sharing website, the first place of call for user created tools, be it from the community at large or an ESRI development team. I have used the Excel and CSV Conversion Toolbox when needing to convert to CSV because of the flakiness of the Table to Table tool.
I just tried this in 10.6.1 running on Windows 10. I added a test field called "PASSING_400_MICROM" and set all values to be "YES". When I went to tun the Table to Table tool and set the output to be a CSV file it truncated the field name to 11 characters. I tried editing the field map and it set it back to 11 characters.
My gut feeling is that this tool is imposing some sort of field name limitation, like it or not.
At this point I would suggest you head over to the ESRI Code Sharing website, the first place of call for user created tools, be it from the community at large or an ESRI development team. I have used the Excel and CSV Conversion Toolbox when needing to convert to CSV because of the flakiness of the Table to Table tool.
edited 3 hours ago
answered 3 hours ago
HornbyddHornbydd
26.3k32757
26.3k32757
add a comment |
add a comment |
The Querying Intern is a new contributor. Be nice, and check out our Code of Conduct.
The Querying Intern is a new contributor. Be nice, and check out our Code of Conduct.
The Querying Intern is a new contributor. Be nice, and check out our Code of Conduct.
The Querying Intern is a new contributor. Be nice, and check out our Code of Conduct.
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%2f311159%2ftable-to-table-converting-arcmap-table-to-csv-file-in-external-location-cuts-col%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
1
Does it have to be a CSV file, you could export to Excel format?
– Hornbydd
3 hours ago
I would prefer to use CSV format if possible: it makes some of the things I do later on in the code a lot easier. But thank you for your Idea! I may use that if I can't figure out this problem.
– The Querying Intern
3 hours ago
What happens if you run the same tool from its dialog with the same parameters?
– PolyGeo♦
3 hours ago
Does the same thing happen with Table Select resources.arcgis.com/en/help/main/10.2/index.html#//… ? It is probable that there is an intermediate DBF file created; if the same thing happens with this tool I would go for user2856's solution feeding in [ x.name for x in arcpy.ListFields(os.path.join(DatabaseLocation, 'Table')) ] to get all fields in the table as the fields parameter.
– Michael Stimson
2 hours ago