dtype

Pandas apply casts None dtype to object or float depending on other outputs

Pandas apply casts None dtype to object or float depending on other outputs Question: I would like to control the output dtypes for apply on a row. foo and bar below have multiple outputs. import pandas as pd def foo(x): return x[‘a’] * x[‘b’], None, x[‘a’] > x[‘b’] def bar(x): return x[‘a’] * x[‘b’], None …

Total answers: 1

Get the percentage of Value dtypes present in a column of dataframe

Get the percentage of Value dtypes present in a column of dataframe Question: I have a pandas dataframe, I need a bifurcation of value present in column of pandas dataframe, data = { "A": [420, 380.2, 390.5,"aplha","beta","gamma"], "B": [520.30, 380.2, 390.5,885.07,56.3,45.2], } in above dataframe in column "A" there are different type of values. Required …

Total answers: 1

pandas read_json dtype=pd.CategoricalDtype does not work but dtype='category' does

pandas read_json dtype=pd.CategoricalDtype does not work but dtype='category' does Question: Is this a known issue that specifying CategoricalDtype dtype at read_json does not convert the column dtype, or is there a mistake in the code? import pandas as pd df = pd.read_json( "./data/data.json", dtype={ #"facility": pd.CategoricalDtype, # does not work "facility": ‘category’, # does work …

Total answers: 1

Pandas int type to date type

Pandas int type to date type Question: i am new to pandas and I try to convert an int type-column to an date type-column . The int in the df is something like: 10712 (first day, then month, then year). I tried solving this with: df_date = pd.to_datetime(df[‘Date’], format=’%d%m%Y’) but I always get the following …

Total answers: 3

pandas astype doesn't work as expected (fails silently and badly)

pandas astype doesn't work as expected (fails silently and badly) Question: I’ve encountered this strange behavior of pandas .astype() (I’m using version 1.5.2). When trying to cast a column as integer, and later requesting dtypes, all seems fine. Until you try to extract the values by row, when you get inconsistent types. Code: import pandas …

Total answers: 1

How to get rid of noise (redundant commas/dots) in decimal values – Python

How to get rid of noise (redundant commas/dots) in decimal values – Python Question: I have a dataset df with two columns ID and Value. Both are of Dtype "object". However, I would like to convert the column Value to Dtype "double" with a dot as decimal separator. The problem is that the values of …

Total answers: 1

How to convert all float64 columns to float32 in Pandas?

How to convert all float64 columns to float32 in Pandas? Question: Is there a generic way to convert all float64 values in a pandas dataframe to float32 values? But not changing uint16 to float32? I don’t know the signal names in advance but just want to have no float64. Something like: if float64, then convert …

Total answers: 2

AttributeError: 'NoneType' object has no attribute 'dtypes'

AttributeError: 'NoneType' object has no attribute 'dtypes' Question: I am trying to sort a subset of my data frame in increasing order with respect to the date index. When I run the sort function only by specifying the axis the code runs. When I add inplace=True I get the error message: AttributeError Traceback (most recent …

Total answers: 2

Change columns names from string to float

Change columns names from string to float Question: I have dataframe with many columns, some of them are strings and some are numbers. Right now when I print the columns names as list I get something like this: df.columns.tolist() >>>[‘name’,’code’,’date’,’401.2′,’405.6′,’507.3’…] I would like to get the numerical columns as float numbers and not as string, …

Total answers: 3