Python Forum
Code for pullng all data in a column - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Code for pullng all data in a column (/thread-39718.html)



Code for pullng all data in a column - EmBeck87 - Mar-31-2023

Hi all, could someone suggest some code for pulling all the data from one column in a dataframe that was pulled in? I have tried a couple different combinations, but they haven't been working. All other data queries with it have worked correctly.


RE: Code for pullng all data in a column - deanhystad - Mar-31-2023

What do you mean by "pull" and "pulled in". If you want the values from a dataframe column.
import pandas as pd

df = pd.DataFrame({"Stuff": (1, 2, 3, 4)})
values = df["Stuff"].values
print(df)
print(values, type(values))
Output:
Stuff 0 1 1 2 2 3 3 4 [1 2 3 4] <class 'numpy.ndarray'>



RE: Code for pullng all data in a column - EmBeck87 - Apr-03-2023

Thanks, it does not show me all the values from the dataframe column though, it shows me a few values at the beginning and a few values at the end, with ... in the middle. How can I see all the values in the column?


RE: Code for pullng all data in a column - deanhystad - Apr-03-2023

You get all the values, but not all the values are printed because the column has too many values. The same thing happens if you print the dataframe Pandas and numpy think (rightfully so) that it is more important to show the start and end values on one page, and intermediate values are less important. To print all the values you can configure printing for numpy, or you can do your own formatting.

This unpacks the array, avoiding the numpy formatting.
import pandas as pd

df = pd.DataFrame({"Stuff": range(10000)})
values = df["Stuff"].values
print(*values)
This tells numpy you want to print all the values.
import pandas as pd
import numpy as np
import sys

np.set_printoptions(threshold=sys.maxsize)
df = pd.DataFrame({"Stuff": range(10000)})
values = df["Stuff"].values
print(values)
Setting numpy printing options is discussed in the excellent numpy documentation.

https://numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html#numpy.set_printoptions


RE: Code for pullng all data in a column - EmBeck87 - Apr-03-2023

Hm, yeah, that didn't really work either. It counted out a list of numbers in an array up to 9,999, it didn't print the values in the column.


RE: Code for pullng all data in a column - deanhystad - Apr-03-2023

What didn't work? My example? My example makes a dataframe with a column that has values 0..9,999. Printing a numpy array of numbers from 0 to 9,999 shows it works. Show me how it doesn't work in your code.