Category : pandas

I am trying to work from csv files located inside of a django app. I am trying to load the file using pandas like: pd.read_csv("…") without success, I keep getting an error. Here is what the directory tree looks like: ├── __pycache__ │   ├── forms.cpython-36.pyc │   ├── models.cpython-36.pyc │   ├── views.cpython-36.pyc │   └── urls.cpython-36.pyc ├── ..

Read more

I need to run a statistic on some data. See how many times a values "j" is next to a value "i". The code that I put hereafter is a gross simplification of what I need to to, but it contains the problem I have. Let’s say that you have this data frame. import numpy ..

Read more

df: home_score away_score 1 0.0 1.0 2 2.0 1.0 3 3.0 2.0 4 0.0 0.0 5 1.0 1.0 Expected result: score — ——- 0 0:1 1 2:1 2 2:1 3 3:2 I am trying df[‘home_score’] = df[‘home_score’].astype(str).str.replace(‘^.*(.d)’, ”, regex=True) to strip the score before combining columns but I am not getting anything.. Also, this code ..

Read more

Let’s take this DataFrame: import itertools import numpy as np import pandas as pd tuples = list(itertools.product(list(‘abcd’), [1,2])) index = pd.MultiIndex.from_tuples(tuples, names=[‘letter’, ‘digit’]) data = np.random.rand(8, 4) df = pd.DataFrame(data, index=index, columns=list(‘abcd’)) I have the following function to get stacked bar plots and save them: def build_stacked_bar_graph(df: pd.DataFrame, xlabel: str, ylabel: str, title: str, saving_name: ..

Read more