Python: Not able to split the dates from csv file












-1















I am trying to plot the dates and prices from a csv. However the dates.append() function is throwing me an error. What can I do to solve this issue?



dates=
prices=

def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-')))
prices.append(float(row[2]))
return
def predicted_price(dates, prices, x):
dates=np.reshape(dates,len(dates),1)

svr_linear= SVR(kernel='linear', C=1e3)
svr_poly= SVR(kernel='poly', C=1e3, degree=2)
svr_rbf= SVR(kernel='rbf', C=1e3, gamma=0.1)

svr_linear.fir(dates,prices)
svr_ploy(dates,prices)
svr_rbf(dates,prices)

plt.scatter(dates,prices, color='black', label='Data')
plt.plot(dates, svr.rbf.predict(dates), color='red', label='RBF Model')
plt.plot(dates, svr.poly.predict(dates), color='blue', label='Poly Model')
plt.plot(dates, svr.linear.predict(dates), color='green', label='Linera Model')

plt.xlabel('Dates')
plt.ylabel('Prices')
plt.title('Regression')

plt.legend()
plt.show()

return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])

getdata('D:\android\trans1.csv')

predicted_prices=predicted_price(dates,price,30)
print(predicted_prices)


Here is the error message.



TypeError Traceback (most recent call last)
<ipython-input-4-63df0e521768> in <module>()
35 return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])
36
---> 37 getdata('D:\android\trans1.csv')
38
39 predicted_prices=predicted_price(dates,price,30)

<ipython-input-4-63df0e521768> in getdata(filename)
7 next(csvFilereader)
8 for row in csvFilereader:
----> 9 dates.append(int(row[4].split('-')))
10 prices.append(float(row[2]))
11 return

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list









share|improve this question

























  • Are you sure the data coming from your csv file is what you expect?

    – Red Cricket
    Nov 22 '18 at 6:28


















-1















I am trying to plot the dates and prices from a csv. However the dates.append() function is throwing me an error. What can I do to solve this issue?



dates=
prices=

def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-')))
prices.append(float(row[2]))
return
def predicted_price(dates, prices, x):
dates=np.reshape(dates,len(dates),1)

svr_linear= SVR(kernel='linear', C=1e3)
svr_poly= SVR(kernel='poly', C=1e3, degree=2)
svr_rbf= SVR(kernel='rbf', C=1e3, gamma=0.1)

svr_linear.fir(dates,prices)
svr_ploy(dates,prices)
svr_rbf(dates,prices)

plt.scatter(dates,prices, color='black', label='Data')
plt.plot(dates, svr.rbf.predict(dates), color='red', label='RBF Model')
plt.plot(dates, svr.poly.predict(dates), color='blue', label='Poly Model')
plt.plot(dates, svr.linear.predict(dates), color='green', label='Linera Model')

plt.xlabel('Dates')
plt.ylabel('Prices')
plt.title('Regression')

plt.legend()
plt.show()

return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])

getdata('D:\android\trans1.csv')

predicted_prices=predicted_price(dates,price,30)
print(predicted_prices)


Here is the error message.



TypeError Traceback (most recent call last)
<ipython-input-4-63df0e521768> in <module>()
35 return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])
36
---> 37 getdata('D:\android\trans1.csv')
38
39 predicted_prices=predicted_price(dates,price,30)

<ipython-input-4-63df0e521768> in getdata(filename)
7 next(csvFilereader)
8 for row in csvFilereader:
----> 9 dates.append(int(row[4].split('-')))
10 prices.append(float(row[2]))
11 return

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list









share|improve this question

























  • Are you sure the data coming from your csv file is what you expect?

    – Red Cricket
    Nov 22 '18 at 6:28
















-1












-1








-1








I am trying to plot the dates and prices from a csv. However the dates.append() function is throwing me an error. What can I do to solve this issue?



dates=
prices=

def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-')))
prices.append(float(row[2]))
return
def predicted_price(dates, prices, x):
dates=np.reshape(dates,len(dates),1)

svr_linear= SVR(kernel='linear', C=1e3)
svr_poly= SVR(kernel='poly', C=1e3, degree=2)
svr_rbf= SVR(kernel='rbf', C=1e3, gamma=0.1)

svr_linear.fir(dates,prices)
svr_ploy(dates,prices)
svr_rbf(dates,prices)

plt.scatter(dates,prices, color='black', label='Data')
plt.plot(dates, svr.rbf.predict(dates), color='red', label='RBF Model')
plt.plot(dates, svr.poly.predict(dates), color='blue', label='Poly Model')
plt.plot(dates, svr.linear.predict(dates), color='green', label='Linera Model')

plt.xlabel('Dates')
plt.ylabel('Prices')
plt.title('Regression')

plt.legend()
plt.show()

return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])

getdata('D:\android\trans1.csv')

predicted_prices=predicted_price(dates,price,30)
print(predicted_prices)


Here is the error message.



TypeError Traceback (most recent call last)
<ipython-input-4-63df0e521768> in <module>()
35 return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])
36
---> 37 getdata('D:\android\trans1.csv')
38
39 predicted_prices=predicted_price(dates,price,30)

<ipython-input-4-63df0e521768> in getdata(filename)
7 next(csvFilereader)
8 for row in csvFilereader:
----> 9 dates.append(int(row[4].split('-')))
10 prices.append(float(row[2]))
11 return

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list









share|improve this question
















I am trying to plot the dates and prices from a csv. However the dates.append() function is throwing me an error. What can I do to solve this issue?



dates=
prices=

def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-')))
prices.append(float(row[2]))
return
def predicted_price(dates, prices, x):
dates=np.reshape(dates,len(dates),1)

svr_linear= SVR(kernel='linear', C=1e3)
svr_poly= SVR(kernel='poly', C=1e3, degree=2)
svr_rbf= SVR(kernel='rbf', C=1e3, gamma=0.1)

svr_linear.fir(dates,prices)
svr_ploy(dates,prices)
svr_rbf(dates,prices)

plt.scatter(dates,prices, color='black', label='Data')
plt.plot(dates, svr.rbf.predict(dates), color='red', label='RBF Model')
plt.plot(dates, svr.poly.predict(dates), color='blue', label='Poly Model')
plt.plot(dates, svr.linear.predict(dates), color='green', label='Linera Model')

plt.xlabel('Dates')
plt.ylabel('Prices')
plt.title('Regression')

plt.legend()
plt.show()

return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])

getdata('D:\android\trans1.csv')

predicted_prices=predicted_price(dates,price,30)
print(predicted_prices)


Here is the error message.



TypeError Traceback (most recent call last)
<ipython-input-4-63df0e521768> in <module>()
35 return svr_rbf.predict(x[4]), svr_linerar(x[4]), svr_poly(x[4])
36
---> 37 getdata('D:\android\trans1.csv')
38
39 predicted_prices=predicted_price(dates,price,30)

<ipython-input-4-63df0e521768> in getdata(filename)
7 next(csvFilereader)
8 for row in csvFilereader:
----> 9 dates.append(int(row[4].split('-')))
10 prices.append(float(row[2]))
11 return

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list






python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:12









Milo Lu

1,65711628




1,65711628










asked Nov 22 '18 at 6:24









varun chauhanvarun chauhan

3910




3910













  • Are you sure the data coming from your csv file is what you expect?

    – Red Cricket
    Nov 22 '18 at 6:28





















  • Are you sure the data coming from your csv file is what you expect?

    – Red Cricket
    Nov 22 '18 at 6:28



















Are you sure the data coming from your csv file is what you expect?

– Red Cricket
Nov 22 '18 at 6:28







Are you sure the data coming from your csv file is what you expect?

– Red Cricket
Nov 22 '18 at 6:28














1 Answer
1






active

oldest

votes


















2














Once you split a string, you are returned a list, the error happens here:



def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-'))) <------------ here
prices.append(float(row[2]))


So instead of converting a string item to int you are converting the results of your .split(), which is a list to int, which is not possible.



If you want to select a target result from your list, you can try with selecting a particular index from the results to test it out:



dates.append(int(row[4].split('-')[0]))





share|improve this answer
























  • No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

    – BernardL
    Nov 22 '18 at 7:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424989%2fpython-not-able-to-split-the-dates-from-csv-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Once you split a string, you are returned a list, the error happens here:



def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-'))) <------------ here
prices.append(float(row[2]))


So instead of converting a string item to int you are converting the results of your .split(), which is a list to int, which is not possible.



If you want to select a target result from your list, you can try with selecting a particular index from the results to test it out:



dates.append(int(row[4].split('-')[0]))





share|improve this answer
























  • No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

    – BernardL
    Nov 22 '18 at 7:01
















2














Once you split a string, you are returned a list, the error happens here:



def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-'))) <------------ here
prices.append(float(row[2]))


So instead of converting a string item to int you are converting the results of your .split(), which is a list to int, which is not possible.



If you want to select a target result from your list, you can try with selecting a particular index from the results to test it out:



dates.append(int(row[4].split('-')[0]))





share|improve this answer
























  • No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

    – BernardL
    Nov 22 '18 at 7:01














2












2








2







Once you split a string, you are returned a list, the error happens here:



def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-'))) <------------ here
prices.append(float(row[2]))


So instead of converting a string item to int you are converting the results of your .split(), which is a list to int, which is not possible.



If you want to select a target result from your list, you can try with selecting a particular index from the results to test it out:



dates.append(int(row[4].split('-')[0]))





share|improve this answer













Once you split a string, you are returned a list, the error happens here:



def getdata(filename):
with open(filename,'r') as csvfile:
csvFilereader=csv.reader(csvfile)
next(csvFilereader)
for row in csvFilereader:
dates.append(int(row[4].split('-'))) <------------ here
prices.append(float(row[2]))


So instead of converting a string item to int you are converting the results of your .split(), which is a list to int, which is not possible.



If you want to select a target result from your list, you can try with selecting a particular index from the results to test it out:



dates.append(int(row[4].split('-')[0]))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 6:32









BernardLBernardL

2,39611130




2,39611130













  • No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

    – BernardL
    Nov 22 '18 at 7:01



















  • No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

    – BernardL
    Nov 22 '18 at 7:01

















No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

– BernardL
Nov 22 '18 at 7:01





No problem and welcome to SO. If any of the answers here solved your question, kindly accept them as an answer by ticking the checkmark below the vote buttons on the left.

– BernardL
Nov 22 '18 at 7:01




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424989%2fpython-not-able-to-split-the-dates-from-csv-file%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()