Creating Dynamic names for columns in a dataframe - dataframes.jl

Suppose I have three columns named a,b and c in a dataframe. I want to prepend/postpend some keyword in front/end of the column names. how can i do this in dataframes.jl?

Related

Pandas move values from row to first three columns

I have a dataframe with two columns. in first column I have a product and second column the name of the client. I have for every product >1 and <4 clients. I need to create a dataframe with first column the product and column B , C, D the client related to the product
Any suggestion

How can I rename the data of a pandas dataframe column?

To be specific. I have a pandas dataframe column called id, its data is 10,20,30, etc
how can I rename the column's data all the way from 1,2,3,4, etc in ascending order instead of 10,20,30?

How to remove rows in a dataframe whose column values are not in a list

I have a dataframe with several different possible values for a particular column. I also have a set that has the column values of rows that I actually care about. I want to update the dataframe such that it removes all rows whose column values are not found in the list I made . How would I do this?
If I get your question then, for a given column col you could do something like this:
df = df.loc[df[col].isin(your_list)]

Pandas and SQLAlchemy: renaming columns during join

I have table A and table B. Both have a column id and a column name.
When I use pd.read_sql() to convert the result of a SQLAlchemy query to a pandas DataFrame, the resulting DataFrame has two columns named id and two columns named name.
The join is executed on the id column, therefore, even if there are two id columns, there won't be any ambiguity since both columns contain the same values. I can simply drop one of the column.
The two columns named name represent an issue because they are not identical: column name of table A represents name of an entity A, while column name of table B represents name of an entity B. At this point I won't know for sure which of the two columns of the DataFrame comes from table A and which from table B. Is there any way to solve this by, for instance, adding a prefix to the column names? More in general, is there any way to exploit the practical pd.from_sql() in this situation?
my_dataframe = pd.read_sql(
session.query(TableA, TableB)
.join(TableB)
.statement,
session.bind)
Note: in this question I am trying to simplify the structure of a more complex preexisting Postgres database. Therefore, it won't be possible to alter the structure of the database.
The solution was actually really simple, but you have to rename each single field:
my_dataframe = pd.read_sql(
session.query(TableA.field1.label('my_new_name1'),
TableA.field2.label('my_new_name2'),
TableB.field1.label('my_other_name2'))
.join(TableB)
.statement,
session.bind)

I want to filter column on specific names in column, and delete these

I have values in my dataframe column that are bad for my data and I need to remove them, I only know how to do this with one row:
df=df[df.name!='susan']
but I want to delete 4 other names within my column