3

I was trying to convert dictionary to pandas dataframe. I have pretty long string in the original dictionary but when I convert into dataframe, I see these strings get shortened. Do anyone know how to store whole string in the dataframe?

Here is some code:

To convert into Dataframe

test = pd.DataFrame(res['Items'][-1]['Item'])

Whole string code from dictionary

res['Items'][-1]['Item']['catchcopy']

Output:

'クリスタルガイザー / クリスタルガイザー(Crystal Geyser) / ミネラルウォーター 500ml 48本 水 ケース☆送料無料☆'

Shortened string code from dataframe

test.catchcopy

Output:

0    クリスタルガイザー / クリスタルガイザー(Crystal Geyser) / ミネラルウォ...
Name: catchcopy, dtype: object
user3368526
  • 2,168
  • 10
  • 37
  • 52

1 Answers1

12

You seem to be confusing the content of the pandas cell with its display. If you want to change the latter, try using display.max_colwidth, like so:

pd.set_option('max_colwidth',40)

Also, if your DataFrame is df and the column name is 'c', you can access the contents of a cell using:

df['c'].values[1]

(for the second cell, e.g.). If you print this, for example, you should see your Python interpreter's rendition of the string.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185