I have a Series, called ‘scores’, with a datetime index. I wish to subset it by quarter and year pseudocode: series.loc[‘q2 of 2013’] Attempts so far: s.dt.quarter AttributeError: Can only use .dt accessor with datetimelike values s.index.dt.quarter AttributeError: ‘DatetimeIndex…
Terminology: A user-defined function object attribute?
According to Python 2.7.12 documentation, User-defined methods: User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object, an unbound user-defined method object, or a class method object. When th…
Python Pandas dataframe reading exact specified range in an excel sheet
I have a lot of different table (and other unstructured data in an excel sheet) .. I need to create a dataframe out of range ‘A3:D20’ from ‘Sheet2’ of Excel sheet ‘data’. All examples that I come across drilldown up to sheet level, but not how to pick it from an exact range…
How to find which version of TensorFlow is installed in my system?
I need to find which version of TensorFlow I have installed. I’m using Ubuntu 16.04 Long Term Support. Answer This depends on how you installed TensorFlow. I am going to use the same headings used by TensorFlow’s installation instructions to structure this answer. Pip installation Run: Note that p…
Count lines of code in directory using Python
I have a project whose lines of code I want to count. Is it possible to count all the lines of code in the file directory containing the project by using Python? Answer To count all the lines of code in the files in a directory, call the “countIn” function, passing the directory as a parameter.
Could pandas use column as index?
I have a spreadsheet like this: I don’t want to manually swap the column with the row. Could it be possible to use pandas reading data to a list as this: Answer Yes, with pandas.DataFrame.set_index you can make ‘Locality’ your row index. If inplace=True is not provided, set_index returns the…
Writing large Pandas Dataframes to CSV file in chunks
How do I write out a large data files to a CSV file in chunks? I have a set of large data files (1M rows x 20 cols). However, only 5 or so columns of the data files are of interest to me. I want to make things easier by making copies of these files with only the columns of
Selenium leaves behind running processes?
When my selenium program crashes due to some error, it seems to leave behind running processes. For example, here is my process list: Here is my code: Sometimes, the browser doesn’t load the webpage elements quickly enough so Selenium crashes when it tries to click on something it didn’t find. Oth…
Django JSON field. ‘module’ object has no attribute ‘JSONField’
I am learning Django and was frustrated by creating a json field in a model. I was trying to create a json field in my model but got error: ‘module’ object has no attribute ‘JSONField’. Here is my class in models.py: I am using django 1.9.8 and postgresql 9.2.13. I need the table creat…
Get HTML table into pandas Dataframe, not list of dataframe objects
I apologize if this question has been answered elsewhere but I have been unsuccessful in finding a satisfactory answer here or elsewhere. I am somewhat new to python and pandas and having some difficulty getting HTML data into a pandas dataframe. In the pandas documentation it says .read_html() returns a list…