So I've successfully imported a csv file as a data frame df
I need to compare successive rows to see which row in the 'Mass' column has the closest value to 20 and then save the entire content of the closest row in a list/any other format.
Any ideas on how I should go about doing this?
Related
I have a data frame as shown in the image below. The first column is Date/Time while the other columns are voltage values. Only a single value column will have a voltage in any row. I would like to merge the voltage columns into a single column. I could do this with a cumbersome for-loop and I am hoping for some panda merge that would do this. I have looked at many merge related posts and could not find, or did not recognize, a solution to this problem. Any help for this would be greatly appreciated.
Dataframe with Date/time in column 1 and values in columns 2 - 5
I am working with incomplete historical data and am using Python to select specific information from TXT files (e.g. via Regex) and write them to .csv tables.
Is it possible to write a certain item or a list of items to new rows in a particular column in an existing CSV file?
I can add individual strings or lists as consecutive new rows or columns to an existing table, but very often, I am only filling in "missing information".
It would be great to find a way to select the next row in the "n"-th column of a CSV table, or to select the column by name / column heading.
Have you considered using Pandas?
It has convenient methods for reading and writing csv-files. Working with columns, rows, and cells is quite intuitive.
It takes a little time to understand the basics of Pandas. but if you plan to work with csv and csv-like data more than once, it is worth it.
This may be a relatively amateur question, but how do I find the last row of a pandas dataframe containing data in python?
I have a poorly structured spreadsheet I am trying to read in and manipulate, but the doc has an excessive number of extra cells below the end of the actual data.
In general, when we import an excel file to pandas as a data frame, the order of the rows is different from the order of the rows in the excel sheet. I want the rows of the data frame to be the same as the rows in that of the excel sheet.
Without looking at any code my guess is you have a parsing issue with pandas. You can try
arx=pd.ExcelFile("yourExcel.xlsx);
//specify your sheets here
parsed = pd.io.excel.ExcelFile.parse(arx, "Sheet1");
If you can show your code, I may be able to help out a bit more
pandas parse
Not sure what you are trying to do but when I had the same issue I used the df.columns to get the order that is in the excel sheet. You can now put it in a list with the correct order.
workbook = ExcelFile('myfile.xlsx')
df = workbook.parse('sheet1')
df_index = list(df.columns) #puts the col index in a list with correct order
lets say you know the column header and want the column number.
df_index.index('column header')
Hope this helped because it really helped me.
I want to import a multicolumn .csv file into Excel. But my aim is to import them with reversed order; e.g. I want the last row of the .csv file be the first in my Excel and the first row of the .csv file be the last row in my Excel. I like something like a macro or an advanced filter for this task.
My .csv contains around 14000 rows so I can't use any manual tricks.
Import data in usual way
Add/insert an extra column to the imported data
Populate the extra column using Series Fill so that it contains the values 1,2,3,...
Select all data (imported and the extra column) and sort on the values in the extra column in descending order
Delete the extra column - data will now be sorted as you require.