Answers for "python extract multiple values from a single cell in a dataframe column using pandas"

0

python return value from single cell dataframe

import pandas as pd

data = ["thing"]
df = pd.DataFrame(data)

print(df.values)
print(df.values[0])
print(df.values[0][0]) #Get first element each time you want to remove the "[]" from a SINGLE value

>>>[['thing']]
>>>['thing']
>>>'thing'
Posted by: Guest on May-17-2021
0

python extract multiple values from a single cell in a dataframe column using pandas

#You have to explode your dataframe if year column contains list:

>>> df.explode('year')
  var1  year
0    a  2025
1    b  2025
1    b  2030
2    c  2023
2    c  2025
2    c  2030
2    c  2040

#If your column contains string representation of a list, you have to eval first:

>>> df.assign(year=pd.eval(df['year'])).explode('year')
  var1  year
0    a  2025
1    b  2025
1    b  2030
2    c  2023
2    c  2025
2    c  2030
2    c  2040
Posted by: Guest on May-08-2022
0

pandas dataframe select columns multiple cell value

subsetDataFrame = df[df['Product'].isin(['Mangos', 'Grapes']) ]
Posted by: Guest on May-08-2022

Code answers related to "python extract multiple values from a single cell in a dataframe column using pandas"

Python Answers by Framework

Browse Popular Code Answers by Language