[Solved] Scraped CSV pandas dataframe I get: ValueError(‘Length of values does not match length of ‘ ‘index’)

You need merge with inner join: print(‘####CURRIES###’) df1 = pd.read_csv(‘C:\\O\\df1.csv’, index_col=False, usecols=[0,1,2], names=[“EW”, “WE”, “DA”], header=None) print(df1.head()) ####CURRIES### EW WE \ 0 can v can 1.90 1 Lanus U20 v Argentinos Jrs U20 2.10 2 Botafogo RJ U20 v Toluca U20 1.83 3 Atletico Mineiro U20 v Bahia U20 2.10 4 FC Porto v Monaco … Read more

[Solved] How do I make a function in python which takes a list of integers as an input and outputs smaller lists with only two values?

If you only want groups of two (as opposed to groups of n), then you can hardcode n=2 and use a list comprehension to return a list of lists. This will also create a group of one at the end of the list if the length of the list is odd: some_list = [‘a’,’b’,’c’,’d’,’e’] [some_list[i:i+2] … Read more

[Solved] How to store missing date(15 min interval) points from csv into new file (15 minutes interval) -python 3.5

try this: In [16]: df.ix[df.groupby(df[‘datetime’].dt.date)[‘production’].transform(‘nunique’) < 44 * 4 * 24, ‘datetime’].dt.date.unique() Out[16]: array([datetime.date(2015, 12, 7)], dtype=object) this will give you all rows for the “problematic” days: df[df.groupby(df[‘datetime’].dt.date)[‘production’].transform(‘nunique’) < 44 * 4 * 24] PS there is a good reason why people asked you for a good reproducible sample data sets – with the one … Read more

[Solved] find number of 1 and 0 combinations in two columns

Assuming you have a pandas dataframe, one option is to use pandas.crosstab to return another dataframe: import pandas as pd df = pd.read_csv(‘file.csv’) res = pd.crosstab(df[‘X’], df[‘Y’]) print(res) Y 0 1 X 0 3 7 1 1 3 A collections.Counter solution is also possible if a dictionary result is required: res = Counter(zip(df[‘X’].values, df[‘Y’].values)) 4 … Read more

[Solved] Matplotlib graph adjusment with big dataset [closed]

Given this dataframe: df.head() complete mid_c mid_h mid_l mid_o time 0 True 0.80936 0.80943 0.80936 0.80943 2018-01-31 09:54:10+00:00 1 True 0.80942 0.80942 0.80937 0.80937 2018-01-31 09:54:20+00:00 2 True 0.80946 0.80946 0.80946 0.80946 2018-01-31 09:54:25+00:00 3 True 0.80942 0.80942 0.80940 0.80940 2018-01-31 09:54:30+00:00 4 True 0.80944 0.80944 0.80944 0.80944 2018-01-31 09:54:35+00:00 Create a 50 moving average: … Read more

[Solved] How to loop over an array of variables with the same form of name? [closed]

If you want to do all the columns in your dataframe: for col in df.columns: sns.countplot(df[col]) . Otherwise, following the pattern in your question: for i in range(1,11): column=’id_’+”{0}”.format(i).zfill(2) sns.countplot(df[column]) that will go through the numbers 1-10 and set column to the correct column name. zfill will make sure that for single digit numbers, column … Read more

[Solved] Any built-in function in pandas/python which converts a list like data into a list

Yes, there is the split function, however before calling it on your string, you must get rid of the [ and ], or else instead of [‘1’, ‘2’, ‘3’, ‘4’], you will get [‘[1’, ‘2’, ‘3’, ‘4]’], so instead of s.split(), we do s[1:-1].split(), also this means your list is strings instead of ints (‘1’ … Read more

[Solved] Add a new column with the list of values from all rows meeting a criterion

Something like this should work… df = pd.DataFrame({‘date’: [‘2017-01-01 01:01:01’, ‘2017-01-02 01:01:01’, ‘2017-01-03 01:01:01’, ‘2017-01-30 01:01:01’, ‘2017-01-31 01:01:01’], ‘value’: [99,98,97,95,94]}) df[‘date’] = pd.to_datetime(df[‘date’]) def get_list(row): subset = df[(row[‘date’] – df[‘date’] <= pd.to_timedelta(‘5 days’)) & (row[‘date’] – df[‘date’] >= pd.to_timedelta(‘0 days’))] return str(subset[‘value’].tolist()) df[‘list’] = df.apply(get_list, axis=1) Output: date value list 0 2017-01-01 01:01:01 99 [99] … Read more

[Solved] Python – How to Compare a column value of one row with value in next row

Use groupby (http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html) Assume your input is saved in a pandas Dataframe (or equivalently save it into csv and read it using pandas.read_csv). Now you can loop over the groups with same S.No values with the following: output = {} for key, group in df.groupby(‘S.No.’): # print key # print group output[key] = {} output[key][‘Details’] … Read more