concatenation

Concatenating CSVs into dataframe with filename column

Concatenating CSVs into dataframe with filename column Question: I am trying to concat multiple CSVs that live in subfolders of my parent directory into a data frame, while also adding a new filename column. /ParentDirectory │ │ ├───SubFolder 1 │ test1.csv │ ├───SubFolder 2 │ test2.csv │ ├───SubFolder 3 │ test3.csv │ test4.csv │ ├───SubFolder …

Total answers: 2

Concat List of DataFrames row-wise – throws pandas.errors.InvalidIndexError:

Concat List of DataFrames row-wise – throws pandas.errors.InvalidIndexError: Question: I am trying to concatenate a list df_l of ~200 Dataframes, which all have the same number of columns and names. When I try to run: df = pd.concat(df_l, axis=0) it throws the error: pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects Following this post …

Total answers: 1

concat 2 df by time index without dropping rows

concat 2 df by time index without dropping rows Question: I convert the ‘time’ columns to index with the setindex function. I have 2 dfs, one with quarter hourly data and time as index. The second one contains hourly data with the identical index but hourly. Now I would like to concat the dfs so …

Total answers: 1

Concat and drop columns function

Concat and drop columns function Question: I normally use the common python codes to concat a few columns and drop the rest. But when I try to create it in a function (def), it doesn’t work. And I am pretty sure that I’m not doing it in the correct way. Can anyone support with this …

Total answers: 1

how to concatenate two lists in python with numbers and strings?

how to concatenate two lists in python with numbers and strings? Question: i want to merge two lists together, but not one after the other list1=[1,2,3,4] list2=[a,b,c,d,e,f] and the output should be list3=[1a,2b,3c,4d,e,f] Asked By: vanessa santiago || Source Answers: Use itertools.zip_longest to iterate over lists of uneven length, and provide a default value (fillvalue) …

Total answers: 1

concatenate features with identical ID in DataFrame

concatenate features with identical ID in DataFrame Question: I have tables that have many features, and these features can have the same ID. How can I check each for ID, then concatenate identical ID features in one row? For example, here’s an example of a simple table stored in a dataframe several features and one …

Total answers: 2

How to merge two DataFrame containing same keys but different values in same columns in python

How to merge two DataFrame containing same keys but different values in same columns in python Question: I have one dataframe that contains all ids df1 = pd.DataFrame({‘id’: [‘A01’, ‘A02’, ‘A03’, ‘A04’, ‘A05’, ‘A06′,’A07’], ‘Name’: [”, ”, ”, ”, ‘MKI’, ‘OPU’,”]}) Second DataFrame that contains some Ids has different name in them df2 = pd.DataFrame({‘id’: …

Total answers: 1

Merge two dataframes by respecting the values in specific columns

Merge two dataframes by respecting the values in specific columns Question: I have two such data frames: df1: DayYear_Count Time 0 2018-03-26 00:00:00 84 00:00:00 2018-03-26 01:00:00 84 01:00:00 2018-03-26 02:00:00 84 02:00:00 2018-03-26 03:00:00 84 03:00:00 2018-03-26 04:00:00 84 04:00:00 df2: Time Temp DayYear_Count 0 00:00:00 6.065167 84 1 01:00:00 5.692167 84 2 02:00:00 …

Total answers: 1

Concatenate text file lines with condition in python

Concatenate text file lines with condition in python Question: I have a text file in this format: 0.jpg 12,13,14,15,16 0.jpg 13,14,15,16,17 1.jpg 1,2,3,4,5 1.jpg 2,3,4,5,6 I want to check if the image name is the same and then concatenate those lines into one line with the following format: 0.jpg 12,13,14,15,16 13,14,15,16,17 1.jpg 1,2,3,4,5 2,3,4,5,6 I …

Total answers: 1