Home
Q&A
Education
Technology
Credit
General
Health
Insurance
Questions
Ask a Question
Combine two columns of text in dataframe in pandas/python
Home
Education
Combine two columns of text in dataframe in...
asked
Jan 28, 2022
in
Education
by
JackTerrance
I have a 20 x 4000 dataframe in python using pandas. Two of these columns are named Year and quarter. I'd like to create a variable called period that makes Year = 2000 and quarter= q2 into 2000q2 Can anyone help with that? Select the correct answer from above options
pandas
machine-learning
python
data-science
1
Answer
0
votes
answered
Jan 28, 2022
by
JackTerrance
Best answer
You can use .map function to join a string with a column in the dataframe. To combine two columns, you can simply use the ‘+’ operator. For example: dataframe["period"] = dataframe["Year"].map(str) + dataframe["quarter"] Hope this answer helps.
Related questions
0
votes
Q: Converting a Pandas GroupBy output from Series to DataFrame
I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked
Jan 28, 2022
in
Education
by
JackTerrance
machine-learning
data-science
pandas
python
scikit-learn
0
votes
Q: pandas reset_index after groupby.value_counts()
I am trying to groupby a column and compute value counts on another column. import pandas as pd dftest = pd. ... Amt, already exists Select the correct answer from above options...
asked
Feb 1, 2022
in
Education
by
JackTerrance
pandas
python
machine-learning
data-science
scikit-learn
0
votes
Q: Get list from pandas DataFrame column headers
I want to get a list of the column headers from a pandas DataFrame. The DataFrame will come from user input so I don ... 'gdp', 'cap'] Select the correct answer from above options...
asked
Jan 26, 2022
in
Education
by
JackTerrance
machine-learning
pandas
python
0
votes
Q: count the frequency that a value occurs in a dataframe column
I have a dataset |category| cat a cat b cat a I'd like to be able to return something like (showing unique values ... cat a 2 cat b 1 Select the correct answer from above options...
asked
Jan 27, 2022
in
Education
by
JackTerrance
python
pandas
dataframe
machine-learning
0
votes
Q: Pandas index column title or name
How do I get the index column name in python pandas? Here's an example dataframe: Index Title Column 1 Apples 1 ... how to do this? Select the correct answer from above options...
asked
Jan 27, 2022
in
Education
by
JackTerrance
machine-learning
python
pandas
dataframe
0
votes
Q: grouping rows in list in pandas groupby
I have a pandas data frame like: a b A 1 A 2 B 5 B 5 B 4 C 6 I want to group by the ... do something like this using pandas groupby? Select the correct answer from above options...
asked
Jan 26, 2022
in
Education
by
JackTerrance
machine-learning
python
pandas
0
votes
Q: How can I replace all the NaN values with Zero's in a column of a pandas dataframe
I have a dataframe as below itm Date Amount 67 420 2012-09-30 00:00:00 65211 68 421 2012-09-09 00 ... solutions would be appreciated. Select the correct answer from above options...
asked
Jan 28, 2022
in
Education
by
JackTerrance
pandas
machine-learning
0
votes
Q: ValueError: DataFrame constructor not properly called! with pandas
def multiple_dfs(xyz_file, sheet, *args): row=2 writer = pd.ExcelWriter(xyz_file, engine='openpyxl') df = pd. ... help me over this? Select the correct answer from above options...
asked
Jan 23, 2022
in
Education
by
JackTerrance
python
python-faq
pandas
0
votes
Q: Select rows from a DataFrame based on values in a column in pandas
I want to select rows from a DataFrame based on values in some column in pandas, How can I do it? I ... WHERE column_name = some_value Select the correct answer from above options...
asked
Jan 22, 2022
in
Education
by
JackTerrance
python
pandas
dataframe
value
0
votes
Q: Pandas Fillna of Multiple Columns with Mode of Each Column
Working with census data, I want to replace NaNs in two columns ("workclass" and "native-country") with the ... way to do this? Select the correct answer from above options...
asked
Feb 3, 2022
in
Education
by
JackTerrance
pandas
python
0
votes
Q: Renaming columns in pandas
I created a dataframe and column labels in pandas and I need to edit in order to replace the original column ... names. Please help? Select the correct answer from above options...
asked
Jan 22, 2022
in
Education
by
JackTerrance
python
replace
pandas
dataframe
0
votes
Q: Python Implementation of OPTICS (Clustering) Algorithm
I'm looking for a decent implementation of the OPTICS algorithm in Python. I will use it to form density-based ... to that cluster. Select the correct answer from above options...
asked
Jan 28, 2022
in
Education
by
JackTerrance
machine-learning
artificial-intelligence
neural-network
data-science
python
0
votes
Q: How to add values from two dataframes according to the persons in first column? Python Pandas
I have 2 data frames df1 Name 2010 2011 0 Jack 25 35 1 Jill 15 20 df2 Name 2010 2011 0 Berry 45 25 1 ... used the code df1.add(df2) Select the correct answer from above options...
asked
Jan 18, 2022
in
Education
by
JackTerrance
data-science
python
0
votes
Q: Convert Python dict into a dataframe
I have a Python dictionary like the following: {u'2012-06-08': 388, u'2012-06-09': 388, u'2012-06-10 ... (my_dict,index=my_dict.keys()) Select the correct answer from above options...
asked
Jan 27, 2022
in
Education
by
JackTerrance
machine-learning
data-science
tensorflow
0
votes
Q: Combine Two Lists in python in dataframe with file name added in one column and content in another
I have a list of files in a folder in my system file_list= ["A", "B", "C"] I Have read the files using ... C How do I accomplish this? Select the correct answer from above options...
asked
Jan 11, 2022
in
Education
by
JackTerrance
data-science
...