New answers tagged

0

Some suggested alternative plotting methods to visualise this data: Histogram of the y-axis. Check the distribution of time intervals df.plot.hist(by='interval', bins=10) #test varying the bin size Plot smaller subsets of the data if the order is important e.g. df[:100].plot() furthermore, if there is periodicity in the data, e.g. daily, hourly etc. you ...


0

You have repeated jobs(JOB0), So its better to create a unique id for the jobs then pivot it based on id and job like df['id'] = df.groupby(['job', 'result']).cumcount() df2 = df.pivot_table(index=['id','job'], columns='result', values='time') Output: result END START id job 0 JOB0 5209 1357 JOB2 2379 2405 JOB3 6578 4010 1 ...


0

You should be able to use pandas.DataFrame.pivot for this as follows: import pandas as pd df2 = df.pivot(index="job", columns="result", values="time")


0

If you just multiply the two dataframes, the missing rows will be filled with NaN values (missing values. You can then simply replace all these with 0.0, or any value. Here is an example: In [1]: import pandas as pd In [2]: df1 = pd.DataFrame(range(6), columns=["A"]) In [3]: df2 = pd.DataFrame(range(8), columns=["A"]) # different ...


0

How about a lambda using df.apply? So, import pandas as pd import numpy as np #initializing variable names variable_names =['var_' + str(i) for i in range(1, 15, 1)] variable_names.insert(0, 'age') Generating random data data =pd.DataFrame(np.random.randint(0,100,size=(100, len(variable_names))), columns=variable_names) # 5 bins data['age_bins'] =pd.cut(...


0

I think first converting the data from a wide to long format should allow you to sort the variables and get the result you want. This would look something like this: import pandas as pd # create example df df = pd.DataFrame({ "age_bin": ["0-10", "10-20", "20-30"], "col1": [5, 4, 2], "col2&...


0

The easiest way to do it for your case is something like this: In [1]: import pandas as pd In [2]: df1 = pd.DataFrame([0, 1, 2, 3, 1, 2, 3, 1, 2], columns=["A"]) In [3]: df2 = pd....


0

First, you need to convert list of list into a list. From link, you can convert a list of lists into a list by declaring the following function. flatten = lambda t: [item for sublist in t for item in sublist] Now all you need is to create dataframe using created lists. data = {"Newspaper":flatten(newspaper), "Title": flatten(title), &...


1

You may use df.groupby(['BirthDate', 'ZipCode']).size().reset_index().rename(columns={0: 'n'}) and now you have a data frame that you can easily manipulate.


1

First answers is close, the only thing you need to do is merge both data frames using two fields. You do not need both data frames to have the same length at all Try: pd.merge(df1, df2, on = ["number","trans"], how = "left")


Top 50 recent answers are included