Skip to content
Advertisement

Tag: pandas

Pandas: Setting no. of max rows

I have a problem viewing the following DataFrame: The problem is that it does not print all rows per default in ipython notebook, but I have to slice to view the resulting rows. Even the following option does not change the output: Does anyone know how to display the whole array? Answer Set display.max_rows: For older versions of pandas (<=0.11.0)

How to add an empty column to a dataframe?

What’s the easiest way to add an empty column to a pandas DataFrame object? The best I’ve stumbled upon is something like Is there a less perverse method? Answer If I understand correctly, assignment should fill:

Random row selection in Pandas dataframe

Is there a way to select random rows from a DataFrame in Pandas. In R, using the car package, there is a useful function some(x, n) which is similar to head but selects, in this example, 10 rows at random from x. I have also looked at the slicing documentation and there seems to be nothing equivalent. Update Now using

Pandas ‘count(distinct)’ equivalent

I am using Pandas as a database substitute as I have multiple databases (Oracle, SQL Server, etc.), and I am unable to make a sequence of commands to a SQL equivalent. I have a table loaded in a DataFrame with some columns: In SQL, to count the amount of different clients per year would be: And the result would be How

How to return a matplotlib.figure.Figure object from Pandas plot function

I have a dt: And use pandas function plot to create a barplot object But I want a <matplotlib.figure.Figure object> instead to pass to other function, just like the object type below: So how can I transform <matplotlib.axes.AxesSubplot object> to <matplotlib.figure.Figure object> or directly return “Figure object” from Pandas plot ? Answer You can get the figure from the axes

How to split a dataframe string column into two columns?

I have a data frame with one (string) column and I’d like to split it into two (string) columns, with one column header as ‘fips’ and the other ‘row’ My dataframe df looks like this: I do not know how to use df.row.str[:] to achieve my goal of splitting the row cell. I can use df[‘fips’] = hello to add

How to drop a list of rows from Pandas dataframe?

I have a dataframe df : Then I want to drop rows with certain sequence numbers which indicated in a list, suppose here is [1,2,4], then left: How or what function can do that ? Answer Use DataFrame.drop and pass it a Series of index labels:

How do I Pass a List of Series to a Pandas DataFrame?

I realize Dataframe takes a map of {‘series_name’:Series(data, index)}. However, it automatically sorts that map even if the map is an OrderedDict(). Is there a simple way to pass a list of Series(data, index, name=name) such that the order is preserved and the column names are the series.name? Is there an easy way if all the indices are the same

Advertisement