I'm attempting to have a script in pandas where it will take the top 6 values from a column, transfer them to the the bottom of a different column, and shift the values of the original column up. An example is below. Thanks!
The original table is the following:
And I need it to end up looking like this.
Related
I have created a dataframe with pandas.
There are more than 1000 rows
I want to merge rows of overlapping columns among them.
For convenience, there are example screenshots made in Excel.
I want to make that form in PYTHON.
I want to make the above data like below
This should be as simple as setting the index.
df = df.set_index('Symbol', append=True).swaplevel(0,1)
Output should be as desired.
I don't know whether this is a very simple qustion, but I would like to do a condition statement based on two other columns.
I have two columns like: the age and the SES and the another empty column which should be based on these two columns. For example when one person is 65 years old and its corresponding socio-economic status is high, then in the third column(empty column=vitality class) a value of 1 is for example given. I have got an idea about what I want to achieve, however I have no idea how to implement that in python itself. I know I should use a for loop and I know how to write conditons, however due to the fact that I want to take two columns into consideration for determining what will be written in the empty column, I have no idea how to write that in a function
and furthermore how to write back into the same csv (in the respective empty column)
[]
Use the pandas module to import the csv as a DataFrame object. Then you can do logical statements to fill empty columns:
import pandas as pd
df = pd.read_csv('path_to_file.csv')
df.loc[(df['age']==65) & (df['SES']=='high'), 'vitality_class'] = 1
df.to_csv('path_to_new_file.csv', index=False)
I wanna create sub dataframes from a main one
My main dataframe will look more or less like this one enter image description here
I wanna be able to have as a sub-dataframe like the following :
first sub dataframe
second sub dataframe
and all the rest for example in an another frame. My goal is to transform correctly my big dataframe into sub dataframe.
Any help will be appreciated, thanks :-)
You can take a rectangular section with numeric indices like this:
df.iloc[4:8, 0:8] # four rows, eight columns
Or you can use loc with column and row labels (but your data seem to be numerically labeled).
first time asking a question:
I'm using
print(df.groupby(['SIDE']).sem())
get correct results when "Sector" column, the last in the data set has a heading but no data but after populating non-numeric data in the column it returns data frame with columns in different order. I'm also using
df.groupby('SIDE').mean()
df.groupby('SIDE').std()
with no issues on the same data, feeling stuck, seems like a bug?
I am fairly new to Python and Pandas and I have not found an answer to this question while searching.
I have multiple csv data files that all contain a date-time column and corresponding data. I wanted to create a series/dataframe that contains a specific span of dates (all data is 1 min interval, so if I wanted to look at July for example I would set the index to start at July and go until the end).
Can I create a series or dataframe that contains only the date-time intervals as an index and does not contain column info? Or would I create an index (the row numbers) and then fill my column with the dates.
I also am unsure of using 'pd.merge' vs 'newdataframe = pd.merge'. When using just pd.merge, nothing comes up in my variable explorer (I use Anaconda's Spyder IDE), only when I use newdataframe = pd.merge does it appear.
Thanks in advance,