[Solved] how to know if a value is in the same range of time in python [closed]

You could group by name, next count values and filter results which have count 3 (because you have 3 years) groups = df.groupby(‘name’).count() result = groups[ groups[‘date’] == 3 ].index.to_list() print(result) Or you could directly count names counts = df[‘name’].value_counts() result = counts[ counts == 3 ].index.to_list() print(‘result:’, result) Minimal working example: I use io.StringIO … Read more

[Solved] Parsing date from fetched dataframe – Python

Here are some potential solutions you could use: import pandas as pd from yahooquery import Ticker from datetime import datetime, date aapl = Ticker(‘aapl’) df = aapl.history(period=’max’, interval=”1d”) df volume low high close open adjclose dividends splits 1980-12-12 14:30:00 117258400.0 0.513393 0.515625 0.513393 0.513393 0.405683 0.0 0.0 1980-12-15 14:30:00 43971200.0 0.486607 0.488839 0.486607 0.488839 0.384517 … Read more

[Solved] I want to group Columns in pandas [closed]

Try this: uniq_accounts = differenc[‘AccountID’].unique() grped = differenc.groupby(‘AccountID’) ## You can get the grouped data for a certain AccountId like this and store in a dictionary: d = {} for account in uniq_accounts: d[account] = grped.get_group(account) ##Now, dictionary has all accounts data in separate dataframes. You can access like this: for key in d.keys(): print(d[key]) … Read more

[Solved] How can I create a vector in pandas dataframe from other attributes of the dataframe?

I think you need: df[‘features’] = df.values.tolist() print(df) Atr1 Atr2 features 0 1 A [1, A] 1 2 B [2, B] 2 4 C [4, C] If you have multiple columns and want to select particular columns then: df = pd.DataFrame({“Atr1″:[1,2,4],”Atr2″:[‘A’,’B’,’C’],”Atr3”:[‘x’,’y’,’z’]}) print(df) Atr1 Atr2 Atr3 0 1 A x 1 2 B y 2 4 … Read more

[Solved] Plotting from excel to python with pandas

Check out these packages/ functions, you’ll find some code on these websites and you can tailor it to your needs. Some useful codes: Read_excel import pandas as pd df = pd.read_excel(‘your_file.xlsx’) Code above reads an excel file to python and keeps it as a DataFrame, named df. Matplotlib import matplotlib.pyplot as plt plt.plot(df[‘column – x … Read more

[Solved] Pandas returning object type instead of values

I think you need aggregation by sum: df3 = df2.groupby(‘Destination Address’, as_index=False)[‘Aggregated Event Count’].sum() Sample: df2 = pd.DataFrame({‘Destination Address’:[‘a’,’a’,’a’, ‘b’], ‘Aggregated Event Count’:[1,2,3,4]}) print (df2) Aggregated Event Count Destination Address 0 1 a 1 2 a 2 3 a 3 4 b df3 = df2.groupby(‘Destination Address’, as_index=False)[‘Aggregated Event Count’].sum() print (df3) Destination Address Aggregated Event … Read more

[Solved] Group by ID and select rows with the newest DATE1 and the oldest DATE2

IIUC, this is a classical groupby+agg. You need to set the dates to a datetime type for meaningful comparisons: (df .assign(DATE_1=pd.to_datetime(df[‘DATE_1’]), DATE_2=pd.to_datetime(df[‘DATE_2’]) ) .groupby(‘ID’) .agg({‘DATE_1’: ‘min’, ‘DATE_2’: ‘max’}) ) output: DATE_1 DATE_2 ID 12 2012-01-01 2021-01-01 13 2010-01-01 2021-01-01 14 2012-01-01 2021-01-01 0 solved Group by ID and select rows with the newest DATE1 and … Read more

[Solved] Read in a csv file as a variable in python

Here a bare code that should do what you are asking: import tkinter as tk from tkinter import filedialog from tkinter import simpledialog import pandas as pd root = tk.Tk() root.withdraw() path = filedialog.askopenfilename(parent=root, filetypes=[(“CSV Files”,”.csv”)]) col1 = simpledialog.askstring(“Input”, “Column 1″, parent=root, initialvalue=”col1”) col2 = simpledialog.askstring(“Input”, “Column 2″, parent=root, initialvalue=”col2”) df = pd.read_csv(path, usecols=[col1, col2]) … Read more

[Solved] How can I combine row values into a new row in pandas [closed]

Use: df.set_index(‘Cities’,inplace=True) df.loc[‘A’]=df.loc[‘A’]+df.loc[‘B’] df=df.drop(‘B’).rename(index={‘A’:’A/B’}).reset_index() set_index(‘Cities’) sets Cities as an index to add using loc. Then A is renamed A / B and cities are reset as a column using reset_index note: if Cities was the index you don need: df.set_index(‘Cities’,inplace=True) 2 solved How can I combine row values into a new row in pandas [closed]

[Solved] select variable from column in pandas

This will give you filtered dataframe with all the columns where Region is Europe and Purchased Bike is Yes agestock = pd.DataFrame({ ‘Region’: {0: ‘Europe’, 1: ‘Europe’, 2: ‘Europe’, 3: ‘APAC’, 4: ‘US’}, ‘Age’: {0: 36, 1: 43, 2: 48, 3: 33, 4: 43}, ‘Purchased Bike’: {0: ‘Yes’, 1: ‘Yes’, 2: ‘Yes’, 3: ‘No’, 4: … Read more