subset first and last consecutive value from pandas df col – python

Advertisements I want to subset a df by returning the first and last consecutive value from a pandas col. Drop_duplciates won’t work because it doesn’t account for consecutive groupings. I’m using .shift() (below) but this only returns the last consecutive value, where I want the first and last. import pandas as pd df = pd.DataFrame({"Item":[‘A’,… Read More subset first and last consecutive value from pandas df col – python

Insert element into list of Pandas Dataframe

Advertisements Have a following DataFrame: df = pd.DataFrame({"booking": [‘A’, ‘B’, ‘C’], "route": [[‘1′,’2′,’3’],[‘5′,’4′,’1’],[‘3′,’6′,’8′]]}) need to insert into each "route" cell the ‘0’ at the beginning of list to get this: df1 = pd.DataFrame({"booking": [‘A’, ‘B’, ‘C’], "route": [[‘0′,’1′,’2′,’3’],[‘0′,’5′,’4′,’1’],[‘0′,’3′,’6′,’8’]]}) and next step is to split route by legs, to get this: df1 = pd.DataFrame({"booking": [‘A’, ‘B’,… Read More Insert element into list of Pandas Dataframe

Convert multi column table into two column

Advertisements let us suppose i want to analyze tourism visitors in different regions/cities of Georgia(Country), here is simple for getting data from the following site : https://www.geostat.ge/en/modules/categories/101/domestic-tourism import pandas as pd data =pd.read_excel("https://geostat.ge/media/52189/visits-by-visited-region.xlsx",skiprows=[0]) data.dropna(axis=0,inplace=True) data.drop(["Year","Quarter","Total","Other regions"],axis=1,inplace=True) data["Country"] ="Georgia" print(data.head()) result is : Tbilisi Adjara A/R Imereti … Kvemo Kartli Shida Kartli Country 0 314.835582 106.598779… Read More Convert multi column table into two column

Resampling and grouping in more than one pandas column

Advertisements Hi i want to convert my dataframe from df = pd.DataFrame({ ‘date’: [ ‘2019-08-01’, ‘2019-12-01’, ‘2019-23-01’, ‘2019-15-01’, ‘2020-26-02’, ‘2020-10-10’, ‘2020-08-10’, ‘2021-01-04’ ], ‘loc’: [ ‘axp’,’axp’, ‘axp’, ‘axp’, ‘axe’, ‘axp’, ‘axp’, ‘axe’ ], ‘category’: [ ‘domestic’, ‘domestic’, ‘domestic’, ‘domestic’, ‘wild’, ‘domestic’, ‘domestic’, ‘wild’ ], ‘status’: [ ‘found’, ‘found’, ‘not found’, ‘found’, ‘found’, ‘found’, ‘found’, ‘not… Read More Resampling and grouping in more than one pandas column

How do I turn a dictionary into a 3 column dataframe?

Advertisements I am turning a dict into a dataframe. My dict is like key:[value]. Dict example; {‘StringAwesome’: PureWindowsPath(‘//server/cool.log’), ‘StringCool’: PureWindowsPath(‘//server/rad.log’)} I want three rows like; 0 — key — value I used orient=index. Which is close, but it gives me; 0 key — value I’d like to end up with; index — columnA — columnB… Read More How do I turn a dictionary into a 3 column dataframe?