dataframe

Aggregate DataFrame base on list values

最后都变了- 提交于 2021-02-11 13:55:08
问题 I have the next problem. I have a list with string values: a = ['word1', 'word2', 'word3', 'word4', ..., 'wordN'] And I have the dataframe with values: +--------------+----------+-----------+ | keywords | impressions | clicks | +--------------+----------+-----------+ | word1 | 1245523 | 12321231 | +--------------+----------+-----------+ | word2 | 4212321 | 12312312 | +--------------+----------+-----------+ ........................................ Please advice me on how to create a specific,

Read in multiple csv into separate dataframes in Pandas

拜拜、爱过 提交于 2021-02-11 13:54:58
问题 I have a long list of csv files that I want to read as dataframes and name them by their file name. For example, I want to read in the file status.csv and assign its dataframe the name status . Is there a way I can efficiently do this using Pandas? Looking at this, I still have to write the name of each csv in my loop. I want to avoid that. Looking at this, that allows me to read multiple csv into one dataframe instead of many. 回答1: You can list all csv under a directory using os.listdir

Read in multiple csv into separate dataframes in Pandas

你说的曾经没有我的故事 提交于 2021-02-11 13:51:06
问题 I have a long list of csv files that I want to read as dataframes and name them by their file name. For example, I want to read in the file status.csv and assign its dataframe the name status . Is there a way I can efficiently do this using Pandas? Looking at this, I still have to write the name of each csv in my loop. I want to avoid that. Looking at this, that allows me to read multiple csv into one dataframe instead of many. 回答1: You can list all csv under a directory using os.listdir

How to find highest combination in dataframe [duplicate]

偶尔善良 提交于 2021-02-11 13:47:07
问题 This question already has answers here : Get the row(s) which have the max value in groups using groupby (11 answers) Closed 9 months ago . I have a data frame that has repeating values in 2 columns and I only want to keep the highest value of each combination. For the following data frame: df = pd.DataFrame( np.array([['A', 'B ', 3], ['A', 'B', 6], ['C', 'D', 9], ['C', 'D', 2], ['C', 'B', 4]])) df how would I get this dataframe as a result: |A|B|6| |C|D|9| |C|B|4| 回答1: Use groupby and

comparing values in two pandas dataframes to keep a running count

*爱你&永不变心* 提交于 2021-02-11 13:41:00
问题 My apologies for the length of this but I want to explain as fully as possible. I am completely stumped on how to solve this. The Setup: I have two dataframes the first has a list of all possible values in the first column there are no duplicate values in this column. Let's call it df_01. Theses are all the common possible values in each list. All additional columns represent independent lists. Each contains a number that represents how many days any given value of all possible values has

R - replace values in dataframe based on two matching conditions

喜夏-厌秋 提交于 2021-02-11 13:37:21
问题 I'm working with lists of spatial data for 20+ different sites (difficult to reproduce here; sorry in advance). I have three data frames associated with each site; each has a 'sample_ID' column and some other shared columns names. What I'm trying to do seems very simple: if the 'sample_ID' values match for two data frames and the column names match, replace the value in DF 1 with that of DF 2 and DF 3 three. Example: # DF 1: SAMPLE_ID CLASS_ID CLASS VALUE 1 0 0 5 2 0 0 5 3 0 0 3 4 0 0 6 5 0 0

How to Convert CSV to Raster in R?

杀马特。学长 韩版系。学妹 提交于 2021-02-11 13:09:05
问题 I have a CSV (value, carbon, latitude, longitude) that I am trying to create a raster from. CSV file sample: Carbon Latitude Longitude coords.x1 coords.x2 1 385 36 74 36 74 2 463 36 74 36 74 3 35 36 74 36 74 4 38 36 74 36 74 5 34 36 74 36 74 6 11 36 74 36 74 7 46 36 74 36 74 8 18 36 74 36 74 9 213 36 74 36 74 10 619 36 74 36 74 11 140 36 74 36 74 12 40 36 74 36 74 13 42 36 74 36 74 14 18 36 74 36 74 15 277 36 74 36 74 16 641 36 74 36 74 17 416 36 74 36 74 18 459 36 74 36 74 19 1073 36 74 36

Add data for the missing dates based on previous hour data in pandas

断了今生、忘了曾经 提交于 2021-02-11 12:51:47
问题 I have a dataframe like below :- id creTimestamp CPULoad instnceId 0 2021-01-22 18:00:00 22.0 instanceA 1 2021-01-22 19:00:00 22.5 instanceA 2 2021-01-22 20:00:00 23.5 instanceA 3 2021-01-22 18:00:00 24.0 instanceB 4 2021-01-22 19:00:00 24.5 instanceB 5 2021-01-22 20:00:00 22.5 instanceB 6 2021-01-24 18:00:00 23.0 instanceA 7 2021-01-24 19:00:00 23.5 instanceA 8 2021-01-24 20:00:00 24.0 instanceA 9 2021-01-24 18:00:00 25.5 instanceB 10 2021-01-24 19:00:00 28.5 instanceB 11 2021-01-24 20:00:00

Pandas DF.AT has wrong value

£可爱£侵袭症+ 提交于 2021-02-11 12:50:34
问题 I'm using Colab to run the following code: import numpy as np import pandas as pd MAP_locs = ["LOAD POINT 1","LOAD POINT 2","DELIVERY POINT"] MAP_SIZE = len(MAP_locs) LOAD_POINT_1 = [] LOAD_POINT_2 = [] DELIVERY_POINT = [] for i in range(10): LOAD_POINT_1.append(0.5) LOAD_POINT_2.append(0.5) DELIVERY_POINT.append(-1) d = {'LOAD POINT 1': LOAD_POINT_1, 'LOAD POINT 2': LOAD_POINT_2, 'DELIVERY POINT': DELIVERY_POINT} df = pd.DataFrame(data=d) VESSEL_Y = 6 VESSEL_X = [1,0,0] VESSEL_X_to_df = MAP

Expand dataframe for each date | Pandas

拜拜、爱过 提交于 2021-02-11 12:44:53
问题 I have a dataframe of user connections where UID represents a user, and date represents the date on which the user made connections (represented by #fans). UID Date #fans 9305 1/25/2015 5 9305 2/26/2015 7 9305 3/27/2015 8 9305 4/1/2015 9 1305 6/6/2015 14 1305 6/26/2015 16 1305 6/27/2015 17 The date range of the dataframe is 01-01-2014 to 12-01-2020. I need to expand the data such that for each user the date should contain each date in the date range and each date should have #fans as total