I have a function in which I want to represent my data like this:

Input is a column:[ 123 125 11 122 ...]
Output:  123  125
         125  11
         11   122

The function in python is like that:

def create_dataset(dataset, look_back=1):
dataX, dataY = [], []
for i in range(len(dataset)-look_back-1):
    a = dataset[i:(i+look_back), 0]
    dataY.append(dataset[i + look_back, 0])
return np.array(dataX), np.array(dataY)

My dataset is represented as 1-grams of integers in a csv file, so I was obliged to use the transpose () of the dataframe to use this function. The problem is that I find the dataframe size null, and the train and test data (after spliting) also empty.

the code is:

dataframe = pd.read_csv("train2.csv")

print(dataframe.shape)  # (0,150)
#dataframe= np.asarray(dataframe)
dataframe = dataframe.transpose()
print(dataframe.shape)   #(150,0)
print(dataframe.size)  # 0

dataset = dataframe.values
dataset = dataset.astype('float32')

# split into train and test sets
train_size = int(len(dataset) * 0.67)
#print (train_size)
test_size = len(dataset) - train_size
train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]
print(len(train), len(test))

print(dataset[0:train_size,:])  #[]
print(train)                    # []
print(test)                     # []

# reshape into X=t and Y=t+1
look_back = 1
trainX, trainY = create_dataset(train, look_back)
testX, testY = create_dataset(test, look_back)

Any solution please?


1 Answer 1


Your first dataframe.shape is showing you that you have no rows. Pandas is probably treating your data as just the column names, so try pd.read_csv('train2.csv', header=None).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.