0

I'm trying to figure out how to convert the entire column of a spreadsheet from an int to a string. The problem I'm having is that I have a bunch of excell spreadsheets whose values I want to upload to our database. Our numbers are 10 digits long and being converted to scientific notation though, so I want to convert all of our numbers from ints into strings before our upload.

I've been trying to do some research, but I can't find any libraries that would convert an entire column -- do I need to iterate row by row converting the numbers to strings?

Thank you.

Harry Baker
  • 93
  • 2
  • 9
  • what format are the files? `xls`? `csv`? – Uriel Oct 26 '16 at 16:00
  • they are in .xlxs – Harry Baker Oct 26 '16 at 16:01
  • I'm not quite understanding what you want- excel can change the format of a column to be scientific. it sounds like your goal is data presentation? – Mohammad Athar Oct 26 '16 at 16:01
  • is it that you want your database to contain strings? have you looked at pandas? it can read/write to xlxs files, and also has a convert_objects feature that might be what you need, also it has an astype feature – Mohammad Athar Oct 26 '16 at 16:04
  • also this: http://stackoverflow.com/questions/17950374/converting-a-column-within-pandas-dataframe-from-int-to-string – Mohammad Athar Oct 26 '16 at 16:05
  • The problem is that we have a lot of excel files with large integers, that are being converted to scientific notion once we import them to SQL server. Since these numbers are ID numbers, we want to import the actual number. The only way we've found that works is to manually convert the these integers to strings before we upload, and I'm wondering if there is an easy programmatic way to convert the entire column in one go. I know that there are libraries to read/write to cells, but I haven't found anything that does entire columns. – Harry Baker Oct 26 '16 at 16:15
  • I tried converting my spreadsheet to a panda data frame and doing applymap(stry), but it didn't actually convert my data. When I printed it post apply map it still said it was an int. – Harry Baker Oct 26 '16 at 16:59

1 Answers1

0

You could try: df['column_name'] = df['column_name'].astype(str)

o-90
  • 17,045
  • 10
  • 39
  • 63
Irfan
  • 21
  • 1