get Keyerror 0 in tf.stack after spliting in train and test dataset

Viewed 111

After I split my dataset into training and test dataset I get key error 0 in tf.stack. If I put all data in the stack everything works. X_train works too. X_test shows key error 0. I have reduced the data and checked manually --> no cell is empty.

Text_3dtensor_all = tf.stack(Tweets_final.Text_Vector, axis=0)

X_train, X_test, y_train, y_test = train_test_split(Tweets_final.Text_Vector,
                                                    Tweets_final.Senti,
                                                    test_size=0.2)

Text_3dtensor_xtrain = tf.stack(X_train, axis=0)

Text_3dtensor_xtest = tf.stack(X_test, axis=0)

Output Console

    Text_3dtensor_xtest = tf.stack(X_test, axis=0)
Traceback (most recent call last):

  File "<ipython-input-11-9573f0d256c6>", line 1, in <module>
    Text_3dtensor_xtest = tf.stack(X_test, axis=0)

  File "C:\Users\Paul\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\util\dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)

  File "C:\Users\Paul\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\array_ops.py", line 1382, in stack
    value_shape = ops.convert_to_tensor(values[0], name=name)._shape_tuple()  # pylint: disable=protected-access

  File "C:\Users\Paul\Anaconda3\envs\embeddings\lib\site-packages\pandas\core\series.py", line 871, in __getitem__
    result = self.index.get_value(self, key)

  File "C:\Users\Paul\Anaconda3\envs\embeddings\lib\site-packages\pandas\core\indexes\base.py", line 4405, in get_value
    return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))

  File "pandas\_libs\index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 90, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 998, in pandas._libs.hashtable.Int64HashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1005, in pandas._libs.hashtable.Int64HashTable.get_item

KeyError: 0

Sample Data

  [[-0.15834129, 0.009571468, -0.099807784, -0.07441181, 0.009008994,0.005190785, 0.0012923682, -0.044878863, -0.023467258, 0.081298664, -0.11089091, -0.037703402, -0.0032897543, -0.010257225, -0.105547115, -0.04132688, 0.03369498, 0.010283905, -0.037393354, 0.05375127, 0.018681044, 0.15729807, 0.00080064684, -0.006218159, -0.09061988, 0.065078676, 0.083635986, -0.0071402146, -0.015305291, 0.23122017, -0.07139613, 0.1832608, 0.02030909, 0.17428705, -0.08419871, -0.030066654, 0.013499449, 0.035009585, 0.091335885, 0.020797074, -0.16686831, 0.015995419, 0.12624139, -0.17242667, -0.00631096, 0.053342905, 0.010088844, 0.1424759, 0.055623576, 0.15188979, -0.008224878, 0.022637803, 0.04056774, -0.00024323042, -0.05188702, 0.13304341, -0.02865698, -0.07008024, 0.034190897, -0.071452014, -0.039574426, 0.078538954, 0.055692673, -0.21134317, 0.049851112, -0.13130145, 0.13642739, -0.060083847, -0.025543641, 0.122547045, 0.0059330165, 0.09833224, 0.0944263, 0.018750597, -0.017913315, -0.023190156, -0.039041206, -0.12587228, -0.011481417, 0.004036048, -0.00041107647, -0.019767849, 0.030014183, -0.0018447589, -0.06636754, 0.03796525, 0.12234162, 0.0080314, 0.060806613, -0.008219364, 0.059646048, 0.118407786, 0.22550285, 0.010877053, 0.009591369, -0.020916127, -0.04730792, 0.042863544, -0.12930852, 0.012552874, ...], [0.086704455, 0.012108797, -0.019956304, -0.024153559, 0.014395769, -0.015940208, 0.02431365, 0.027654245, -0.053400856, -0.023548301, 0.053436637, -0.02769893, -0.009622073, -0.0431756, 0.008849693, -0.079510786, 0.07489725, -0.008680338, 0.04310928, -0.13323471, -0.009098269, 0.0022847825, 0.028767591, 0.013285508, -0.058834, -0.024997406, -0.03591905, -0.0047532558, -0.03082858, -0.0099356705, -0.049918532, 0.020872943, 0.041038267, -0.0896674, 0.045975085, 0.011876725, -0.06074377, 0.014792646, 0.078690484, 0.030319005, 0.012596002, -0.009793039, 0.047137156, 0.0056614703, -0.023184128, 0.054300644, -0.012018312, 0.057756376, 0.031985484, -0.11268355, 0.046225976, -0.009900588, -0.002799028, 0.026883556, -0.007610197, 0.03817895, 0.027677275, -0.021869667, -0.0074380105, 0.025748631, -0.023320127, 0.059401434, -0.011470987, -0.024153246, -0.04472476, 0.0230652, -0.0050362945, -0.11213815, 0.00052199326, 0.023425307, 0.031651415, -0.023728443, 0.02841579, 0.038982064, -0.069004916, -0.0253998, -0.025054758, -0.022112787, -0.043690987, -0.043477025, 0.031118592, 0.0129863545, 0.008230219, 0.0680808, -0.10163962, 0.007120654, -0.00440606, -0.035121925, -0.016719034, 0.01067192, -0.008551922, 0.075124845, -0.013535939, -0.0121086305, 0.022979863, -0.031998605, 0.02565514, 0.05041366, 0.09597272, 0.011722933, ...], [-0.0011870201, -0.013872736, -0.009382487, -0.032390088, 0.031281058, -0.07816208, 0.033973064, -0.018822132, -0.060160182, -0.009778567, -0.011631626, -0.019628238, 0.08803632, -0.0057291486, 0.00709982, -0.026086396, 0.032895423, 0.045064747, 0.00734179, -0.0421323, -0.063167796, 0.0054061334, 0.01536034, -0.015474774, 0.028069219, 0.02559016, -0.025270933, 0.02940068, -0.03549522, 0.0026786022, 0.024683112, 0.012990372, -0.0130805, 0.0005901727, -0.017880881, -0.0084165465, 0.018961266, -0.017659891, 0.0718774, 0.05330669, 0.051087305, 0.043120217, -0.0016508899, 0.032468632, 0.06869453, 0.065017976, 0.017559484, -0.02180021, -0.004032635, -0.028523622, 0.02134573, -0.0017242669, 0.007984889, 0.013486145, -0.014406161, 0.005090992, 0.047986954, -0.010824936, -0.035775963, -0.031121727, -0.037562713, 0.03042981, 0.04705608, 0.0078351945, -0.015669882, 0.0020288026, 0.017314661, -0.019491112, 0.02523409, 0.055017695, 0.012373059, -0.014256537, 0.034605853, -0.0008305816, -0.012629594, -0.012383624, -0.0430717, -0.06768049, 0.014133727, -0.0048148464, -0.018584743, -0.014701272, 0.024763346, 0.032083217, 0.032571036, 0.032060795, 0.011470803, 0.061815068, -0.014500423, -0.018530296, 0.010037919, 0.024224138, 0.01923909, 0.029818472, 0.000243401, 0.047100324, 0.04560112, -0.042037208, 0.03490892, 0.030142983, ...], [0.04182121, 0.008163791, -0.028963646, -0.004353024, 0.024046749, -0.057768807, -0.07352497, -0.043677103, 0.010483424, 0.111403845, -0.013131081, -0.030632054, -0.04216818, -0.025356159, 0.027209952, -0.011660966, 0.03313974, -0.017725483, 0.09743175, -0.049295675, -0.008691082, -0.06368008, 0.016392326, -0.030274814, -0.109683156, 0.013280746, -0.014577368, 0.015298607, -0.03200246, -0.10078612, 0.14064476, 0.06463073, -0.023865504, -0.13710703, -0.043015197, 0.06456448, -0.09437832, 0.07922542, 0.20538276, -0.044611923, -0.033689022, -0.06887673, 0.031378653, -0.0013913326, 0.0009001391, 0.1022019, -0.019528063, 0.048488483, -0.02478933, -0.18258333, 0.05377145, -0.02427454, -0.008653902, 0.009144518, -0.09082124, 0.062007695, 0.03493821, 0.0048299497, -0.02331091, -0.013471293, -0.04222092, -0.0022358424, -0.03485405, 0.03884484, -0.0047138473, -0.03202302, 0.038074907, -0.092969894, 0.023831371, 0.10942554, 0.039495036, -0.05557391, 0.008439191, 0.09226151, -0.03527808, 0.019908793, -0.018379113, 0.02715014, 0.0043538413, -0.01889908, -0.07502878, -0.057405375, 0.006172494, 0.10215883, -0.024249315, -0.05981265, -0.011151466, -0.053348854, 0.088795215, -0.0023238189, -0.029286526, 0.035579294, -0.064610355, -0.030297754, 0.023483276, 0.017390883, 0.0039020653, 0.10939492, 0.102789305, 0.054498058, ...], [0.03573832, 0.012006024, 0.009255514, 0.043773085, 0.026037162, -0.048033483, -0.05653116, -0.0154731525, 0.057956204, 0.06261198, -0.019914247, -0.045843765, -0.020884942, -0.09229424, -0.03666846, -0.0748351, 0.07372944, -0.029338434, 0.094713196, -0.20177945, -0.038297057, -0.09263473, 0.08832433, -0.042030804, -0.05101782, -0.026596725, 0.032194108, -0.037531666, -0.058601316, -0.16696972, 0.2380288, 0.005871353, 0.006291518, -0.04006859, 0.039107043, 0.028678736, -0.011769886, 0.10361074, 0.22280395, 0.028999215, 0.07932643, 0.05162085, 0.07099715, -0.038852684, -0.030641463, 0.095357, -0.0026486951, 0.022645805, 0.0010081257, -0.30801833, -0.028913569, -0.009396356, 0.039501842, 0.031008095, -0.09055042, 0.02884408, -0.043528017, 0.023627348, -0.027436113, -0.05550758, -0.024424545, 0.011522574, -0.07541359, 0.0016586278, -0.054438584, -0.037426606, 0.00027026236, -0.04603196, 0.0045975214, 0.018302053, 0.04666264, 0.030034935, -0.013351361, 0.09934097, -0.031199448, -0.019691955, 0.017345317, 0.0039141322, -0.012410779, 0.018565916, 0.061377198, -0.049475204, -0.062677264, 0.040716283, -0.13547066, 0.20527439, -0.001257365, 0.043298654, 0.12359369, 0.02550198, -0.0992586, 0.1666899, 0.009656187, 0.034281213, -0.0056018396, -0.0016019344, -0.0070985868, 0.0006887565, 0.106914416, 0.04153388, ...], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.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