Pandas column separation using .loc [duplicate] - python

This question already has answers here:
Selecting multiple columns in a Pandas dataframe
(22 answers)
Closed last month.
I am an amateur user.
I watched many videos but I couldn't figure out this error.
How can I keep PERSON_WGHT, LOS, and IDC_DC_CD_1 as a columns for all rows that is 386816.

If you need to select multip0le columns from all the records then use df[[column_list]].
df_new = df[['PERSON_WGHT', 'LOS', 'IDC_DC_CD_1']]

Related

Python Pandas combine [duplicate]

This question already has answers here:
How do I Pandas group-by to get sum?
(11 answers)
Closed last month.
Let's say I have the Python pandas dataframe below, I want to combine the amount paid column based on employee ID.
[dataframe]
Well try:
dataframe.groupby('EMPLOYEE_ID')['AMOUNT_PAID'].sum()

In pandas, how to turn a dataframe into tidy data? [duplicate]

This question already has answers here:
How do I melt a pandas dataframe?
(3 answers)
Convert columns into rows with Pandas
(6 answers)
Closed last year.
In python and pandas I have a dataframe that I need to turn into tidy data to make charts easier
The original data is like this:
I want to transform into a dataframe, with the transposition of the data and adapting column names:
Please is there a way in python to do this?
Use melt:
out = df.melt('year', var_name='localization', value_name='number_of_tests')
You can also use:
out = df.set_index('year').rename_axis(columns='localization').unstack() \
.rename('number_of_tests').reset_index()

How to query from multiindex dataframe containing data and time as index [duplicate]

This question already has answers here:
selecting from multi-index pandas
(7 answers)
Closed 1 year ago.
Check this image of dataframe
I've posted the picture of dataframe I am working with, I want to pull out data from specific times of a certain date
I've tried
stockdf.loc[("2015-01-01")].loc['09:17:00']
stockdf.loc[("2015-01-01","09:17:00"),:]
Both do not work.
Just try:
stockdf.loc[("2015-01-01", "09:17:00")]
If they're dates:
stockdf.loc[(pd.to_datetime("2015-01-01").date(), pd.to_datetime("09:17:00").time())]

Filter columns of the dataframe with specific string [duplicate]

This question already has answers here:
how to read certain columns from Excel using Pandas - Python
(6 answers)
Selecting multiple columns in a Pandas dataframe
(22 answers)
Closed 2 years ago.
I need to filter data of the columns according to string values, for example, I only need the columns that contain:
['CEMENTO MELON', 'G_CTRL_TE_DIEGO_DE_ALMAGRO','G_CTRL_EO_CANELA_2']
todos = []
for f in glob.glob('*.xlsx'):
#Here must go the code
todos.append(df)
I would greatly appreciate your help.

Python Pandas- Select rows where multiple columns are null [duplicate]

This question already has answers here:
Select data when specific columns have null value in pandas
(3 answers)
How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?
(6 answers)
Closed 4 years ago.
I want to select rows which have multiple columns(4 in the following example) as null values. I have used the following code:
data[(data['relevent_experience'].isnull())&data['education_level'].isnull())&data['major_disciplne'].isnull())&data['relevent_experience'].isnull())]
This is a very complicated code. Is there a cleaner way to do the same thing?

Categories

Resources