Python Forum
readall() not working in python3.5
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
readall() not working in python3.5
#1
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] = value
instead.

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
Reply
#2
Please, always, include the error traceback verbatim
Reply
#3
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
Reply
#4
Does no one know this at all then, am I the only person to have come across this issue?
Reply
#5
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/Python2orPy...erences.3F


[url=https://wiki.python.org/moin/Python2orPython3#What_are_the_differences.3F][/url]
Reply
#6
Thanks for link Lars+60
Reply
#7
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020