Python Forum
Code for pullng all data in a column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code for pullng all data in a column
#1
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.
Reply
#2
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'>
Reply
#3
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?
Reply
#4
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/g...intoptions
Reply
#5
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.
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code to set column width 1418 11 1,253 Jan-20-2024, 07:20 AM
Last Post: Pedroski55
  Returning Column and Row Data From Spreadsheet knight2000 0 453 Oct-22-2023, 07:07 AM
Last Post: knight2000
  Database that can compress a column, or all data, automatically? Calab 3 1,197 May-22-2023, 03:25 AM
Last Post: Calab
  split txt file data on the first column value shantanu97 2 2,451 Dec-29-2021, 05:03 PM
Last Post: DeaD_EyE
  Retrieving a column from a data set using a function Bayle 6 2,362 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 1,569 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  How to filter out Column data From Multiple rows data? firaki12345 10 5,149 Feb-06-2021, 04:54 AM
Last Post: buran
  Data extraction from a table based on column and row names tgottsc1 1 2,419 Jan-09-2021, 10:04 PM
Last Post: buran
  update column in one data frame with value of column from another data frame flexer 0 1,793 Dec-04-2020, 03:29 PM
Last Post: flexer
  Merge CSV Column using Pandas Data Frames davidlang 1 2,627 May-01-2020, 02:43 PM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020