Categories
Mastering Development

R: How to mutate new ID by modifying previous ID?

I asked the question(How to mutate a new column by modifying another column?) Now I have another problem. I have to use more ‘untidy’IDs like, df1 <- data.frame(id=c(“A-1″,”A-10″,”A-100″,”b-1″,”b-10″,”b-100”),n=c(1,2,3,4,5,6)) from this IDs, I want to assign new ‘tidy’ IDs like, df2 <- data.frame(id=c(“A0001″,”A0010″,”A0100″,”B0001″,”B0010″,”B0100”),n=c(1,2,3,4,5,6)) (now I need capital ‘B’ instead of ‘b’) I tried to use str_pad […]

Categories
Mastering Development

Interpreting function returning DataFrame in Python

This may sound a bit desperate as it is kind of urgent and I cannot find the answer with a short amount of time elsewhere. It’s about a function I came across: def func1(df, level): … … … df1 = … df2 = … df3 = … … … return df1, df2, df3 if __name__ […]

Categories
Mastering Development

Excel .json Import Error: The Type of Current Preview Value is Too Complex to Display [closed]

Main Problem: I’m trying to import .json to excel for pivot table. The data contains 4.000.000 rows and i have to create pivot table for summarize the data (My company uses excel because of company structure, so i have to). When i import the json file, excel shows this error: “The type of current preview […]

Categories
Development

Return a changed list in R via lapply(), but objects in list not changed

I’m trying to loop through a list of data frames, dropping columns that don’t match some condition. I want to change the data frames such that they’re missing 1 column essentially. After executing the function, I’m able to change the LIST of data frames, but not the original data frames themselves. df1 <- data.frame( a […]

Categories
Development

Get the nearest distance with two geodataframe in pandas

Here is my first geodatframe : !pip install geopandas import pandas as pd import geopandas city1 = [{‘City’:”Buenos Aires”,”Country”:”Argentina”,”Latitude”:-34.58,”Longitude”:-58.66}, {‘City’:”Brasilia”,”Country”:”Brazil”,”Latitude”:-15.78 ,”Longitude”:-70.66}, {‘City’:”Santiago”,”Country”:”Chile “,”Latitude”:-33.45 ,”Longitude”:-70.66 }] city2 = [{‘City’:”Bogota”,”Country”:”Colombia “,”Latitude”:4.60 ,”Longitude”:-74.08}, {‘City’:”Caracas”,”Country”:”Venezuela”,”Latitude”:10.48 ,”Longitude”:-66.86}] city1df = pd.DataFrame(city1) city2df = pd.DataFrame(city2) gcity1df = geopandas.GeoDataFrame( city1df, geometry=geopandas.points_from_xy(city1df.Longitude, city1df.Latitude)) gcity2df = geopandas.GeoDataFrame( city2df, geometry=geopandas.points_from_xy(city2df.Longitude, city2df.Latitude)) City1 City Country Latitude Longitude […]

Categories
Development

Python Pandas: merge returns Nan

I have two dataframes i.e. df1 and df2. df1 is df1 date time 0 2015-04-01 00:00:00 1 2015-04-01 00:30:00 2 2015-04-01 01:00:00 3 2015-04-01 01:30:00 4 2015-04-01 02:00:00 Datatype of df1 is: date object time timedelta64[ns] dtype: object df2 is: INCIDENT_TIME INTERRUPTION_TIME MINUTES 0 2015-01-08 03:00:00 1056.0 1 2015-01-10 23:30:00 3234.0 2 2015-04-01 01:00:00 3712.0 […]

Categories
Development

Having trouble creating entry widget in tkinter python

I’m having some trouble creating an entry widget with tkinter. I have already created several buttons and check boxes but I cannot figure out how to properly get the entry to work. Here is my code: import tkinter import tkinter.ttk from tkinter import filedialog from tkinter import * def create_widgets_in_first_frame(): # Create the label for […]

Categories
Development

Filtering dataframe by comparing two dataframe columns containing different formatted phone numbers

I have one dataframe, df1, containing a list of US phone numbers in the following format: Area code + phone numbers And it contains international phone numbers This dataframe is a couple of hundred rows long df1[‘phoneNumber’] = [‘123456789’, ‘1115559999’,’1112223333′, ‘442071231234’] I have another dataframe, df2, containing millions of phone records in several different formats […]

Categories
Development

lapply and loop – cannot coerce type ‘closure’ to vector of type ‘character’

I am trying to perform a grepl function on a list of 250 dataframes each with about 50,000 single words in each cell like this: df1 <- c(“this”,”is”,”the”,”first”,”sentence”,…) df2 <- c(“this”,”is”,”the”,””,”sentence”,…) df3 <- c(“now”,”the”,”third”,”sentence”,”appears”,…) I want to know how often individual words appear so I decided to put all the dataframes in a list like […]

Categories
Development

Change duplicated column names after merging multiple tables in python

I have merged 4 files into one. df1: ID name location case pass 1 John NY tax Y 2 Jack NJ payment N 3 John CA remote Y 4 Rose MA income Y df2: ID name location case pass 1 John NY car N 2 Jack NJ train Y 3 John CA car Y 4 […]