Hi I have a following df: I would like to to add the latitude and longitude columns after the city name, while where there are NaN and # value I would like to leave new cells empty or with 0 value. what I tried: the error that I get: Answer You can try:
Tag: pandas
TypeError: object cannot be converted to an IntegerDtype
I want to replace nan values in B with A in df: df: df data types: I tried: and it caught error: Answer Use numpy.where for avoid floats in output column: If need strings in output:
Combining unique elements of a DataFrame in a list
I’ll try to ask my question as clearly as possible. I have the following DataFrame which looks like this Now I want to keep values unique to each player only once. Ideally in a list, but that’s not a big deal. For example, player A and B play soccer so I don’t want soccer in the output. tennis appears twice,
Create new pd dataframe column that gives a date based on day and week starting data
I have a pandas dataframe that has two columns, the first column is ‘Week Starting’ and the other is ‘Day’. I wanna create a new column that uses the data from the other two columns to give a full date. For example, from the table below, the first entry of the new column should be 5/04/2021 and the second should
how to slice pandas dataframe columns with default values instead of error
I have a following set of dataframes I am trying to slice them so that I only have [‘col1’, ‘col3’, ‘col4’] While I’m able to achieve that using slicing df[[‘col1′,’col3’, ‘col4’]], in the case that col4 doesn’t exist , it gives an error. Is it possible to put a default value e.g. nil or 0 in case col4 doesn’t exist
In Pandas, how do I convert a number column to discrete values quickly?
I have a dataframe with an Integer column, which I need to convert to discrete value bands, I am currently doing this using apply with my own function, as seen bellow, however this is rather slow, is there any way to quickly do this? Caller function here: My data look like this: Answer IIUC and given the mix of types
Error: ‘str’ object has no attribute ‘shape’ while trying to covert datetime in a dataframe
Consider a I have a column called ‘test’ of a dataframe. The column elements are like this: I want to make the each column elements of the dataframe as 2016-04-01. Based on this I have written a code which is working fine in spyder but when I am trying to apply it to Jupyter Notebook it is showing some error
Merging time series data so that column values are fitted into dictionaries
I have two time-series data frames that track the same certain countries throughout the same amount of time, but the variables they track for each observation represent vastly different things. For example, the first data frame is like so: Tracking variable ‘A’: Country 01/01/2020 01/02/2020 01/03/2020 … 04/25/2021 AFG 0 0 1 … 5000 CHN 0 20 50 … 0
limit pandas .loc method output within a iloc range
I am looking for a maximum value within my pandas dataframe but only within certain index range: This gives me a pandas.core.frame.DataFrame type output with multiple rows. I specifically need the the index integer of the maximum value within iloc[430:440] and only the first index the maximum value occurs. Is there anyway to limit the range of the .loc method?
How to remove a certain number of characters at the start of a string
I have a dataset of NHL Free Agents, however they are numbered as a part of the name. I am trying to make “1. Alex Ovechkin” look like “Alex Ovechkin”. Basically just trying to delete the number, period, and space between. I have used the following code to successfully delete the numbers for the first 10 entries, however at entry