![]() |
readall() not working in python3.5 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: readall() not working in python3.5 (/thread-768.html) |
readall() not working in python3.5 - iFunKtion - Nov-04-2016 Hi there, So I can't get readall() to work in python 3.5, I can get it to work on a raspberry pi, but with no access to said pi, I am assuming that it is running python 3.4. So I have had to use read() instead, which does work, but it is throwing up the following warning now suggesting: buiys["datestamp"] = np.array(buys["timestamp"]).astype("datetime64[s]")be changed in format to: .loc[row_indexer,col_indexer] = valueinstead. But I can't work out how to do this with my current code, I am simply trying to access the column headed "timestamp" from (what I am assuming is a text file) Here is a snippet of the code I am using, matplotlib, pandas, numpy and urllib are all imported: from matplotlib import pyplot as plt import matplotlib.dates as mdates import matplotlib.ticker as mticker import tkinter as tk from tkinter import ttk import urllib import json import pandas as pd import numpy as np data_link = 'https://btc-e.com/api/3/trades/btc_usd?limit=2000' data = urllib.request.urlopen(data_link) data = data.read().decode("utf-8") data = json.loads(data) data = data["btc_usd"] data = pd.DataFrame(data) buys = data[(data['type']=="bid")] print (buys) buys["datestamp"] = np.array(buys["timestamp"]).astype("datetime64[s]") buyData = (buys["datestamp"]).tolist()Typing this straight into python3 window reproduces the error. How should I be accessing the data from this file (which I am assuming is a dictionary of dictionaries) Regards iFunK RE: readall() not working in python3.5 - Larz60+ - Nov-04-2016 Please, always, include the error traceback verbatim RE: readall() not working in python3.5 - iFunKtion - Nov-04-2016 Apologies, is this what you are referring to: >>> buys["datestamp"] = np.array(buys["timestamp"]).astype("datetime64[s]") __main__:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy RE: readall() not working in python3.5 - iFunKtion - Nov-07-2016 Does no one know this at all then, am I the only person to have come across this issue? RE: readall() not working in python3.5 - Larz60+ - Nov-07-2016 The code you provide has absolutely no reference to readall(), so how do you expect that will help? In this case it's not needed, but it would be good to provide proper code snippet in the future. readall() is read() in python3. It would be good to read the differences doc: https://wiki.python.org/moin/Python2orPython3#What_are_the_differences.3F [url=https://wiki.python.org/moin/Python2orPython3#What_are_the_differences.3F][/url] RE: readall() not working in python3.5 - Blue Dog - Nov-07-2016 Thanks for link Lars+60 RE: readall() not working in python3.5 - iFunKtion - Nov-09-2016 I'm sorry, I posted the code that I had got to, as I assumed that putting readall() where read() was would just get replies to use read() as the readall() command simply did not work. The research i had done on the matter had led me to understand that readall() was never a command in python, as I have not found it in any of the python docs online, and that it worked as part of a package, which as someone trying to learn is very difficult to navigate. The original code that I am learning from uses readall() so it must have worked at some time, and the only difference I could find was that the tutorials were on Windows and using Python 3.4 and I am using Linux Mint and python 3.5.2. I understand that python is supposed to be completely cross platform, so I had dismissed the Windows/Linux option and I found one forum post on Stack Exchange that pointed out that readall() worked upto python 3.4, but not after that, however it was only the one place amongst about 5 pages of google search. For clarity, I am learning and working exclusively with python 3 currently, I am aware of some of the differences and have read the differences page, but until I am a better programmer, I think trying to learn both of them would be confusing so I am learning python 3 as I am only writing scripts that are standalone at the current time. I have since had to reinstall OS (Raspberry pi so no big deal) and wrote the script again and it worked. I am suspecting there may have been a typo or something that I could not spot, shame I never got to the bottom of it, but for the moment the issue seems to be resolved. |