In a python function I want to show the user a pandas dataframe and let the user edit the cells in the dataframe. My function should use the edited values in that dataframe (i.e. they should be saved).
I've tried pandasgui, but it does not seem to return the edits to the function.
Is there a function/library I can use for this?
Recently solved this problem with dtale
import pandas as pd
import dtale
df = pd.read_csv('table_data.csv')
dt = dtale.show(df) # create dtale with our df
dt.open_browser() # bring it to a new tab (optional)
df = dt.data # connect all the updates from dtale gui and our df
# (so rn if u edit any cell, you will immediately get the result saved in ur df)
Yesterday I came across with some bugs while using dtale. Filtering broke my changes and creating some new rows I dont need.
Usually I use dtale and pandasgui together.
Hope it helps!
Related
I would like to know if there's any function that I can use for flag (when there's pop up date. for ex:row 188,189,190...etc.) without using loop. please see attached excel file.
Thank you so much!
an example
If you are ok with using pandas...
import pandas as pd
path = 'path\to\file'
df = pd.read_csv(path)
flags = ~df['pop up'].isna()
I'm new on this site so be indulgent if i make a mistake :)
I recently imported a csv file on my Jupyter notebook for a student work. I want use some of data of specific column of this file. The problem is that after import, the file appear as a table with 5286 lines (which represent dates and hours of measures) in a single column (that compiles all variables separated by ; that i want use for my work).
I don't know how to do to put this like a regular table.
I used this code to import my csv from my board :
import pandas as pd
data = pd.read_csv('/work/Weather_data/data 1998-2003.csv','error_bad_lines = false')
Output:
Desired output: the same data in multiple columns, separated on ;.
You can try this:
import pandas as pd
data = pd.read_csv('<location>', sep=';')
I'm trying to capture AND present data in a table format after the script is finished. The website I am using is http://en.wikipedia.org/wiki/List_of_all-time_NFL_win-loss_records And the logic is working as such:
I run the command, it opens to the URL
I then go to the URL http://en.wikipedia.org/wiki/List_of_all-time_NFL_win-loss_records
I proceed to copy any selected rows/columns from the Table/chart
I then go back to my IDE (Jupyter Notebook) and it takes the captured data and spits it out
I can select the data on that particular webpage and copy it using my cursor by highlighting and selecting “copy”. It will then spit out all that I have selected and copied to my clipboard.
So far, my script that I wrote, is working to only capture the data and then spit it back out as is (unformatted).
PROBLEM: I would like the data I captured to be presented in a table format after I have finished selecting it and have it copied in my clipboard.
I realize I need to probably write the logic for the data I captured to be then be formatted. What would be the best approach for accomplishing this?
Below is my code that I have written so far:
Here is my code:
import numpy as np
Import pandas as pd
from pandas import Series, Dataframe
website='http://en.wikipedia.org/wiki/NFL_win_loss_records'
web browser.open(website)
nfl_frame= pd.read_clipboard(Sep='\t')
nfl_frame
You can read your data directly to DataFrame with pandas.read_html
import pandas as pd
WIKI_URL = 'http://en.wikipedia.org/wiki/List_of_all-time_NFL_win-loss_records'
df = pd.read_html(WIKI_URL,header=0)[1]
df.head() # in jupyter or print(df.head()) to show a table with first 5 rows
As pd.read_html returns a list. In them are tables that are in that HTML/URL. I set header to first raw, and selected the second element of the list which is the table you are looking for.
I am new to Python, coming from MATLAB. In MATLAB, I used to create a variable table (copy from excel to MATLAB) in MATLAB and save it as a .mat file and whenever I needed the data from the MATLAB, I used to import it using:
A = importdata('Filename.mat');
[Filename is 38x5 table, see the attached photo]
Is there a way I can do this in Python? I have to work with about 35 such tables and loading everytime from excel is not the best way.
In order to import excel tables into your python environment you have to install pandas.
Check out the detailed guideline.
import pandas as pd
xl = pd.ExcelFile('myFile.xlsx')
I hope this helps.
Use pandas:
import pandas as pd
dataframe = pd.read_csv("your_data.csv")
dataframe.head() # prints out first rows of your data
Or from Excel:
dataframe = pd.read_excel('your_excel_sheet.xlsx')
I have a .csv file which looks as follows:link
I want to open this file using pandas and edit the column Coordinate by adding a constant value of 756 to each value in it. Finally, I want the changes to be reflected in the .csv file.
How do I do that?
Edit: What I had been doing is as follows (#EdChum):
df = pd.read_csv('C:/TestBook1.csv')
df = df[['Coordinate','Speed']]
Coord = df['Coordinate']
Coord = Coord + 756
This is where I was going wrong. From here it would have been a messy affair to save changes into the .csv file.
you can also type:
df["Coordinate"] = df["Coordinate"] + 756
#EdChum: Thanks for your comment. It kind of fired me up. I was unnecessarily complicating things for myself. Following is what I did:
df = pd.read_csv('C:/TestBook1.csv')
df = df[['Coordinate','Speed']]
df['Coordinate']+=756
df.to_csv('C:/TestBook1.csv')
Initially I was loading all the values of the column into a variable and trying to find a way to save it. After your comment I thought of experimenting and I am glad that it worked for me.
Define path where csv file is located
Location = r'C:\\'
df = pd.read_csv(Location,header=None)
df["Coorinate"].values +756
Do not forget to import pandas package
import pandas as pd